fix(npf): check if vectors has element before accessing them

This commit is contained in:
Gustavo "Guz" L. de Mello
2024-05-02 14:01:08 -03:00
parent 25e94fc788
commit 73d55c84b0
2 changed files with 9 additions and 5 deletions

View File

@@ -78,8 +78,10 @@ impl<'a> TryFrom<&'a Node<'a, RefCell<Ast>>> for objects::Post {
}
NodeValue::BlockQuote => {
let mut p = Self::try_from(node.children())?.join_content("\n\n");
if let BlockValue::Text(ref mut t) = &mut p.content[0] {
t.subtype = Some(BlockTextSubtype::Indented);
if p.content.len() > 0 {
if let BlockValue::Text(ref mut t) = &mut p.content[0] {
t.subtype = Some(BlockTextSubtype::Indented);
}
}
Ok(p)
}

View File

@@ -84,9 +84,11 @@ impl Post {
})
.flatten()
.collect::<Vec<_>>();
let block = &mut self.content[0];
if let BlockValue::Text(ref mut t) = block {
t.text = String::from(t.text.strip_suffix(sep).unwrap_or(&t.text));
if self.content.len() > 0 {
let block = &mut self.content[0];
if let BlockValue::Text(ref mut t) = block {
t.text = String::from(t.text.strip_suffix(sep).unwrap_or(&t.text));
}
}
self
}