Skip to content

fix: Let tree-building parses report the locations streaming ones do - #131

Open
sideshowbarker wants to merge 1 commit into
masterfrom
no-stream-locations
Open

sideshowbarker wants to merge 1 commit into
masterfrom
no-stream-locations

Conversation

@sideshowbarker

Copy link
Copy Markdown
Member

Problem: In the Nu HTML Checker, with --no-stream, each HTML parser message got a range that started at the start of the document — or at the end of the previous message — so its extract and highlight took in all the markup from there to the error. And a checker message reported at an end tag got no location at all.

Cause: When its streamability violation policy is ALLOW, HtmlParser uses its SAXTreeBuilder, which builds the whole tree before TreeParser replays it as SAX events. So a SAX consumer that tracks locations had none for any error the parser reported, which the checker needs to find where the range of each error starts. Also, SAXTreeBuilder never set an element’s end locator, so the replay gave endElement events no location.

Fix: As SAXTreeBuilder builds the tree, it now sends the events a streaming parse emits, at the same points, to any handlers set with the new HtmlParser.setTreeBuildingWiretap() — so those handlers get the same locations a streaming parse gives, interleaved with the parser’s errors. SAXTreeBuilder also now sets the end locator of each element it pops.

Fixes validator/validator#2168

Problem: In the Nu HTML Checker, with --no-stream, each HTML parser
message got a range that started at the start of the document — or at
the end of the previous message — so its extract and highlight took in
all the markup from there to the error. And a checker message reported
at an end tag got no location at all.

Cause: When its streamability violation policy is ALLOW, HtmlParser uses
its SAXTreeBuilder, which builds the whole tree before TreeParser
replays it as SAX events. So a SAX consumer that tracks locations had
none for any error the parser reported, which the checker needs to find
where the range of each error starts. Also, SAXTreeBuilder never set an
element’s end locator, so the replay gave endElement events no location.

Fix: As SAXTreeBuilder builds the tree, it now sends the events a
streaming parse emits, at the same points, to any handlers set with the
new HtmlParser.setTreeBuildingWiretap() — so those handlers get the same
locations a streaming parse gives, interleaved with the parser’s errors.
SAXTreeBuilder also now sets the end locator of each element it pops.

Fixes validator/validator#2168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--no-stream gives wrong start positions and extracts for parser errors

1 participant