Skip to content

Commit

Permalink
Balance pos pushes when ignoring comments
Browse files Browse the repository at this point in the history
Fixes netvl#225
  • Loading branch information
kornelski committed Jun 2, 2023
1 parent 129ab96 commit 6c13445
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/reader/parser/outside_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ impl PullParser {
}
} else { None };
self.inside_whitespace = true; // Reset inside_whitespace flag
self.push_pos();

// pos is popped whenever an event is emitted, so pushes must happen only if there will be an event to balance it
// and ignored comments don't pop
if t != Token::CommentStart || !self.config.c.ignore_comments {
self.push_pos();
}
match t {
Token::OpeningTagStart if self.depth() > 0 || self.encountered < Encountered::Element || self.config.allow_multiple_root_elements => {
if let Some(e) = self.set_encountered(Encountered::Element) {
Expand Down
11 changes: 11 additions & 0 deletions tests/event_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ fn issue_replacement_character_entity_reference() {
);
}

#[test]
fn push_pos_issue() {
let source = "<n><!---->L<!----><!----><!----><!----><!----><!----><!----><!----><!---->\"<!----><!---->L<!----><!----></n>";
let parser = ParserConfig::new()
.cdata_to_characters(true)
.ignore_comments(true)
.coalesce_characters(false)
.create_reader(std::io::Cursor::new(source));
parser.into_iter().for_each(|e| { e.unwrap(); });
}

// clones a lot but that's fine
fn trim_until_bar(s: String) -> String {
match s.trim() {
Expand Down

0 comments on commit 6c13445

Please sign in to comment.