Skip to content

Fix stack overflow on text inside noscript elements - #277

Open
eXpl0it3r wants to merge 1 commit into
masterfrom
fix/noscript-text
Open

eXpl0it3r wants to merge 1 commit into
masterfrom
fix/noscript-text

Conversation

@eXpl0it3r

Copy link
Copy Markdown
Collaborator

Text directly inside a <noscript>, e.g. <body><noscript>Enable JS</noscript></body> or the same inside <head>, crashes the parser with a stack overflow, which takes down the whole process. HtmlKit tokenizes the noscript content as raw text, so HtmlParser reparses every data token inside a noscript as markup, but for plain text the reparse yields the same data token again with the noscript still being the current box, so it recurses forever. Additionally the raw text gets split into several data tokens at every < and each reparse starts again at the noscript, so with <noscript><p><b>a</b><i>b</i></p></noscript> everything after <b> ended up as a sibling of the <p> instead of inside it.

The parser now collects all data tokens of the noscript first, parses the whole content once with the noscript box as root and treats data directly in that root as text. Since the library doesn't support scripting, that's how the HTML spec wants noscript content to be handled.

How to test this PR?

CI should succeed. HtmlParserTests.Noscript_TextIsParsedAsText covers text inside noscript in the body and the head and crashes the test host on master, HtmlParserTests.Noscript_MarkupKeepsItsStructure covers the split content and fails on master.

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.

1 participant