Repository navigation
Restrict HTML tag whitespace to spaces, tabs and line endings - #316
Open
anubhavlal07 wants to merge 1 commit into
Open
anubhavlal07 wants to merge 1 commit into
anubhavlal07 wants to merge 1 commit into
Conversation
Avoids cubic backtracking on NBSP runs after an attribute's = (commonmark#315).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The HTML tag regexes in
lib/common.jsuse JS\s, which also matches U+00A0 and other Unicode spaces.UNQUOTEDVALUE([^"'=<>\x00-\x20]+) matches U+00A0 too. So after<a x=, a run of NBSP can be split three ways:\s*after=, the unquoted value, and the trailing\s*before/?>. When the closing>is missing, the anchored type-7 block-start regex (^(?:OPENTAG|CLOSETAG)\s*$) and the inlinereHtmlTag` try every split, which is cubic:<a x=\sis also wrong per spec 0.31.2. An attribute, an attribute value specification, an open tag and a closing tag all allow only "spaces, tabs, and up to one line ending" as whitespace. Start condition 7 for HTML blocks allows only spaces and tabs between the tag and the end of the line.Fix
lib/common.js: addTAGWHITESPACE = "[ \t\r\n]"and use it in place of\sinATTRIBUTEVALUESPEC,ATTRIBUTE,OPENTAGandCLOSETAG. An NBSP run after=can now match only the unquoted value, so the split ambiguity is gone.lib/blocks.js: change the trailing\s*$inreHtmlBlockOpen[7]to[ \t]*$.The fix changes how a few inputs render, all to match the spec:
<a+ NBSP +x=1>is no longer a tag, in blocks or inline.<a>+ NBSP no longer starts a type-7 HTML block.<a x=+ NBSP +>is still a tag, because NBSP is a valid unquoted value character.dist/is not touched.Tests
test/regression.txt: four examples: the three cases above and the unclosed<a x=+ NBSP case from the issue. Without the fix, the<a+ NBSP +x=1>example and the<a>+ NBSP example fail.test/test.js: a pathological case for<a x=followed by 1000 and 10000 NBSP. Without the fix, the 10000 case does not finish within 2 minutes. With the fix it runs in a few ms.make testreports 760 passed, 0 failed, andmake lintis clean.make benchonbench/samples/README.mdwas noisy on my machine, with readings between 1,300 and 3,900 ops/sec for both versions. Alternating runs gave before 3,828 / 3,972 / 3,303 ops/sec and after 3,161 / 3,247 / 3,477 ops/sec. To reduce the noise, I loaded both builds into one process and alternated them over 8 rounds of 300 parses each. Median time was 79 ms before and 78 ms after onREADME.md, and 312 ms before and 304 ms after on all ofbench/samples/*.md.Fixes #315