aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/emitter.rs2
-rw-r--r--src/tokenizer.rs2
-rw-r--r--tests/test_spans.rs15
4 files changed, 17 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 259447b..8579e4d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,8 @@
* Fixed attribute value spans being wrong for values containing character references.
+* Fixed most error spans mistakenly being empty.
+
* Fixed some error spans being off-by-one
(`eof-*`).
diff --git a/src/emitter.rs b/src/emitter.rs
index a014025..d28b11b 100644
--- a/src/emitter.rs
+++ b/src/emitter.rs
@@ -339,7 +339,7 @@ impl<O: Offset> Emitter<O> for DefaultEmitter<O> {
*self_closing = true;
}
Token::EndTag(_) => {
- self.emit_error(Error::EndTagWithTrailingSolidus, offset - 1..offset - 1);
+ self.emit_error(Error::EndTagWithTrailingSolidus, offset - 1..offset);
}
_ => {
debug_assert!(false);
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 6cf930f..871074e 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -185,7 +185,7 @@ impl<R: Reader + Position<O>, O: Offset, E: Emitter<O>> Tokenizer<R, O, E> {
| Error::EofInDoctype
| Error::EofInScriptHtmlCommentLikeText
| Error::EofInTag => self.reader.position()..self.reader.position(),
- _ => self.reader.position() - 1..self.reader.position() - 1,
+ _ => self.reader.position() - 1..self.reader.position(),
};
self.emitter.emit_error(error, span);
}
diff --git a/tests/test_spans.rs b/tests/test_spans.rs
index e839f53..28342ea 100644
--- a/tests/test_spans.rs
+++ b/tests/test_spans.rs
@@ -213,9 +213,20 @@ fn doctype_id_spans() {
fn annotate_errors(html: &'static str) -> String {
let mut labels = Vec::new();
for token in tokenizer(html) {
- if let Token::Error { error, span } = token {
- labels.push((span, error.code()));
+ let Token::Error { error, span } = token else {
+ continue;
+ };
+
+ if span.start == span.end {
+ if span.start != html.len() {
+ panic!("empty error spans are only allowed at the very end of the source (for eof errors)");
+ }
+ } else {
+ assert!(span.start < span.end);
+ assert!(span.end <= html.len());
}
+
+ labels.push((span, error.code()));
}
annotate(html, labels)
}