Repository navigation
Description
Summary
(Disclaimer: I used Claude code to write this issue to make sure it's as complete and understandable as possible)
If you run the validator with --no-stream, every message from the HTML parser (tokenizer or tree builder) gets the wrong start position. It is set to the start of the document (1:1), or to the end of the previous message in output formats that include source extracts (e.g. JSON). So extract and hiliteStart/hiliteLength cover the whole region from that point to the error instead of just the bad markup. The end position (lastLine/lastColumn) is correct. Without --no-stream the output is correct.
Reproduced with 26.11.4 (26b30ab) (current main) and earlier commits.
Likely cause
MessageEmitterAdapter.messageWithRange() gets the range start from SourceCode.rangeStartForRangeLast(). That method picks the nearest location recorded before the error, and those locations are recorded by LocationRecorder as SAX events reach the wiretap set up in SimpleDocumentValidator.getWiretap().
- Streaming (default):
SimpleDocumentValidatorsetssetStreamabilityViolationPolicy(FATAL), soHtmlParserusesSAXStreamer. SAX events are emitted while tokenizing, so the location of the preceding tag is already recorded when the parser reports an error. --no-stream: the policy staysALLOW, soHtmlParserusesSAXTreeBuilder. SAX events are only replayed after the whole document has been parsed, so no locations are recorded yet when parser errors are reported. The only earlier locations are the document start and, when an extract is emitted, therangeLastof earlier messages (added inSourceCode.rangeEndError()). That explains why gnu output starts at 1.1 every time while JSON starts at the end of the previous message.
URL for document that reproduces the problem
n/a
HTML/CSS/SVG snippet that reproduces the problem
<!DOCTYPE html>
<html lang="en">
<title>Test</title>
<br />
<p>Some text</p>
</span>Checker error messages
n/aSpec links/citations
No response
Steps to reproduce
vnu --stdout --format gnu - < repro.html
vnu --stdout --format gnu --no-stream - < repro.html(Passing repro.html as a file argument instead of on stdin gives the same result.)
Expected behavior
--no-stream should only change how the document is parsed internally. Message locations and extracts should be the same as without it.
Actual behavior
Without --no-stream (correct):
:4.1-4.6: info: Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.
:6.1-6.7: error: Stray end tag “span”.
With --no-stream (wrong, both ranges start at the beginning of the document):
:1.1-4.6: info: Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.
:1.1-6.7: error: Stray end tag “span”.
With --format json the extracts are affected. The first message's extract is the whole document up to the error. The second message starts right after the end of the first one (4.7; firstColumn is omitted because it equals lastColumn) instead of at 6.1, so its highlight also covers the unrelated <p>Some text</p> line:
// default (streaming)
{"lastLine":4,"lastColumn":6,"firstColumn":1,
"extract":"t</title>\n<br />\n<p>So","hiliteStart":10,"hiliteLength":6}
{"lastLine":6,"lastColumn":7,"firstColumn":1,
"extract":" text</p>\n</span>\n","hiliteStart":10,"hiliteLength":7}
// --no-stream
{"lastLine":4,"firstLine":1,"lastColumn":6,"firstColumn":1,
"extract":"<!DOCTYPE html>\n<html lang=\"en\">\n<title>Test</title>\n<br />\n<p>So","hiliteStart":0,"hiliteLength":59}
{"lastLine":6,"firstLine":4,"lastColumn":7,
"extract":"le>\n<br />\n<p>Some text</p>\n</span>\n","hiliteStart":10,"hiliteLength":25}On a real page this produces extracts that are hundreds of characters long.
Screenshots or screen recordings
No response
Activity
sideshowbarker commentedon Nov 9, 2026
Thanks — nice catch. Should be fixed now, in the latest release.
fix: Report the right message locations with --no-stream