Skip to content

noscript is an island - #2537

Merged
jhy merged 2 commits into
masterfrom
noscript
Jul 26, 2026
Merged

jhy merged 2 commits into
masterfrom
noscript

Conversation

@jhy

@jhy jhy commented Jul 26, 2026

Copy link
Copy Markdown
Owner

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:

<noscript><img src="//example.com/1x1.gif"></noscript>

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:

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.
@jhy jhy added this to the 1.23.1 milestone Jul 26, 2026
@jhy jhy added the improvement An improvement / new feature idea label Jul 26, 2026
@jhy
jhy merged commit a682fd5 into master Jul 26, 2026
22 checks passed
@jhy
jhy deleted the noscript branch July 26, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement An improvement / new feature idea

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant