Skip to content

Commit

Permalink
Fix panic on incomplete closing frontmatter fence
Browse files Browse the repository at this point in the history
Closes GH-121.

Reviewed-by: Titus Wormer <[email protected]>
  • Loading branch information
nokome authored Aug 9, 2024
1 parent d0788c9 commit 2c83b0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/construct/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,16 @@ fn resolve(tokenizer: &mut Tokenizer) {
inject_index = child_index + 1;
}

if let Some(mut exits) = tokenizer.tokenize_state.document_exits[line].take() {
let mut exit_index = 0;
while exit_index < exits.len() {
exits[exit_index].point = point.clone();
exit_index += 1;
if line < tokenizer.tokenize_state.document_exits.len() {
if let Some(mut exits) = tokenizer.tokenize_state.document_exits[line].take() {
let mut exit_index = 0;
while exit_index < exits.len() {
exits[exit_index].point = point.clone();
exit_index += 1;
}

child.map.add(inject_index, 0, exits);
}

child.map.add(inject_index, 0, exits);
}

line += 1;
Expand Down
6 changes: 6 additions & 0 deletions tests/frontmatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ fn frontmatter() -> Result<(), message::Message> {
"should not support 2 markers in a closing fence"
);

assert_eq!(
to_html_with_options("---\n--\n", &frontmatter)?,
"<hr />\n<p>--</p>\n",
"should not panic if newline after 2 marker closing fence"
);

assert_eq!(
to_html_with_options("---\n----", &frontmatter)?,
"<hr />\n<hr />",
Expand Down

0 comments on commit 2c83b0d

Please sign in to comment.