Repository navigation
Conversation
This treats each `noscript` element as a parsing island: build its fallback markup as a DOM subtree, while preventing malformed content from changing the surrounding parser state (as it would per the spec if handled in non-scripting mode) This keeps fallback elements inspectable in both head and body, preserves normal HTML tokenization within the island, and allows the markup to round-trip serialize. Fragment context boundaries remain synthetic and non-closeable.
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.
This changes how jsoup parses
<noscript>content.The HTML specification defines two behaviours depending on whether scripting is enabled, but neither is especially useful for jsoup.
When scripting is enabled, the contents are parsed as text, making fallback markup opaque to callers:
When scripting is disabled, the contents are parsed as normal HTML.
That makes the elements inspectable, but their parsing rules can affect the surrounding document.
For example, an element that is not permitted in the document head can move the parser into the body, causing subsequent head content to be misplaced.
Historically, jsoup used a mixture of these behaviours:
<noscript>content in the head was treated as text, while content in the body was parsed into the DOM.This change instead treats
<noscript>as a parsing island.Its fallback markup is parsed into an inspectable DOM subtree, while malformed or context-sensitive markup inside it cannot disrupt the structure outside the
<noscript>element.This gives callers a representation closer to the source markup without requiring them to account for the specification’s scripting modes.
The result also round-trip serializes without allowing parsing state from the fallback content to escape into the surrounding document.
This is an intentional deviation from the HTML specification.
Callers with site-specific
<noscript>handling, or code that works around jsoup’s previous head/body behaviour, should review how the resulting DOM is used.Relevant specification sections:
noscriptelement