From 585c6349c9b84345364350f020e8f987a8b44f7b Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 30 Aug 2023 09:50:53 +0200 Subject: fix!: off-by-one end-tag-with-trailing-solidus span --- CHANGELOG.md | 5 ++++- src/emitter.rs | 9 ++++++--- src/machine.rs | 2 +- tests/test_spans.rs | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8579e4d..13d3cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ * `emit_error` now takes a span instead of an offset. + * Several provided offsets have been changed to be more sensible. + Affected are: `set_self_closing` + * token types * `AttributeOwned`: The `value_offset` field has been replaced with `value_span`. @@ -39,7 +42,7 @@ * Fixed most error spans mistakenly being empty. * Fixed some error spans being off-by-one - (`eof-*`). + (`eof-*`, `end-tag-with-trailing-solidus`). ### 0.5.0 - 2023-08-19 diff --git a/src/emitter.rs b/src/emitter.rs index d28b11b..9334121 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -89,7 +89,7 @@ pub trait Emitter { /// /// If the current token is an end tag, the emitter should emit the /// [`Error::EndTagWithTrailingSolidus`] error. - fn set_self_closing(&mut self, offset: O); + fn set_self_closing(&mut self, slash_offset: O); /// Assuming the _current token_ is a doctype, set its "force quirks" flag to true. /// @@ -329,7 +329,7 @@ impl Emitter for DefaultEmitter { self.emit_token(Token::Doctype(doctype)); } - fn set_self_closing(&mut self, offset: O) { + fn set_self_closing(&mut self, slash_offset: O) { let tag = self.current_token.as_mut().unwrap(); match tag { Token::StartTag(StartTag { @@ -339,7 +339,10 @@ impl Emitter for DefaultEmitter { *self_closing = true; } Token::EndTag(_) => { - self.emit_error(Error::EndTagWithTrailingSolidus, offset - 1..offset); + self.emit_error( + Error::EndTagWithTrailingSolidus, + slash_offset..slash_offset + 1, + ); } _ => { debug_assert!(false); diff --git a/src/machine.rs b/src/machine.rs index 159a8a0..082ab68 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -903,7 +903,7 @@ where }, State::SelfClosingStartTag => match slf.read_char()? { Some('>') => { - slf.emitter.set_self_closing(slf.reader.position()); + slf.emitter.set_self_closing(slf.reader.position() - 2); slf.state = State::Data; slf.emit_current_tag(); Ok(ControlToken::Continue) diff --git a/tests/test_spans.rs b/tests/test_spans.rs index 28342ea..a2e5d3e 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -267,7 +267,7 @@ fn error_end_tag_with_trailing_solidus() { let html = "Do you start or do you end? "; assert_snapshot!(annotate_errors(html), @r###" Do you start or do you end? - ^ end-tag-with-trailing-solidus + ^ end-tag-with-trailing-solidus "###); } -- cgit v1.2.3