Skip to content

Commit

Permalink
fix crash when text events are emitted inside HTML blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Sep 22, 2024
1 parent 45d4106 commit 7772303
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions v2/src/markdown/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ impl<'input, I: Iterator<Item = (Event<'input>, Range)>> HtmlBlockReader<'input,
return None;
}
Event::Html(html) => html,
// Text event is emitted when tags are preceded by spaces like " <p></p>"
Event::Text(text) => text,
event => unreachable!("unexpected event: {event:?}"),
};
self.index = 0;
Expand Down Expand Up @@ -1250,4 +1252,17 @@ mod tests {
assert_eq!(offset, expected, "{before:?}, {after:?}");
}
}

#[test]
fn text_event_inside_html_block() {
let target = MarkdownContent::new(" <p>foo</p>".to_string(), None);
let parser = MarkdownParser::new(&target, None, ());
let mut buf = Vec::new();
let () = parser.write_to(&mut buf).unwrap();
let buf = String::from_utf8(buf).unwrap();
assert!(
buf.contains(r#"{"t":"html","raw":" <p>foo</p>"}"#),
"expected HTML block is not contained: {buf:?}",
);
}
}

0 comments on commit 7772303

Please sign in to comment.