diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/tokenizer.rs | 14 | ||||
-rw-r--r-- | tests/test_spans.rs | 10 |
3 files changed, 18 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a9101..259447b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ * Fixed attribute value spans being wrong for values containing character references. +* Fixed some error spans being off-by-one + (`eof-*`). + ### 0.5.0 - 2023-08-19 #### Features diff --git a/src/tokenizer.rs b/src/tokenizer.rs index db4fda6..6cf930f 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -178,10 +178,16 @@ impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Tokenizer<R, O, E> { /// Just a helper method for the machine. #[inline] pub(crate) fn emit_error(&mut self, error: Error) { - self.emitter.emit_error( - error, - self.reader.position() - 1..self.reader.position() - 1, - ); + let span = match error { + Error::EofBeforeTagName + | Error::EofInCdata + | Error::EofInComment + | Error::EofInDoctype + | Error::EofInScriptHtmlCommentLikeText + | Error::EofInTag => self.reader.position()..self.reader.position(), + _ => self.reader.position() - 1..self.reader.position() - 1, + }; + self.emitter.emit_error(error, span); } /// Assuming the _current token_ is an end tag, return true if all of these hold. Return false otherwise. diff --git a/tests/test_spans.rs b/tests/test_spans.rs index 840e8e1..e839f53 100644 --- a/tests/test_spans.rs +++ b/tests/test_spans.rs @@ -265,7 +265,7 @@ fn error_eof_before_tag_name() { let html = "<"; assert_snapshot!(annotate_errors(html), @r###" < - ^ eof-before-tag-name + ^ eof-before-tag-name "###); } @@ -277,7 +277,7 @@ fn error_eof_in_comment() { let html = "<!--"; assert_snapshot!(annotate_errors(html), @r###" <!-- - ^ eof-in-comment + ^ eof-in-comment "###); } @@ -286,7 +286,7 @@ fn error_eof_in_doctype() { let html = "<!doctype html"; assert_snapshot!(annotate_errors(html), @r###" <!doctype html - ^ eof-in-doctype + ^ eof-in-doctype "###); } @@ -295,7 +295,7 @@ fn error_eof_in_script_html_comment_like_text() { let html = "<script><!--"; assert_snapshot!(annotate_errors(html), @r###" <script><!-- - ^ eof-in-script-html-comment-like-text + ^ eof-in-script-html-comment-like-text "###); } @@ -304,7 +304,7 @@ fn error_eof_in_tag() { let html = "</sarcasm"; assert_snapshot!(annotate_errors(html), @r###" </sarcasm - ^ eof-in-tag + ^ eof-in-tag "###); } |