Skip to content

Conversation

@sideshowbarker
Copy link
Member

@sideshowbarker sideshowbarker commented Dec 30, 2025

This change brings us into conformance with the “make breaking out of foreign content apply in innerHTML” requirements from the HTML spec PR at whatwg/html#6399 — and into interoperability with current WebKit and Blink behaviour, making fragment parsing break out of foreign content in the same way document parsing does.

Before this code change, when parsing elements like p, div, and nobr inside SVG/MathML via innerHTML, they would stay in the foreign namespace. But, with this change, they now correctly “break out”, and are created in the HTML namespace.

TreeBuilder.java

  • Start tags: Remove fragment-only restriction on break-out behavior
  • End tags: Allow </p> and `
    q to reach mode-handling-in-fragment case
  • Use currentPtr > 0 to preserve context element when popping

Copy link
Member

@hsivonen hsivonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

This change brings us into conformance with the “make breaking out of
foreign content apply in innerHTML” requirements from the HTML spec PR
at whatwg/html#6399 — and into interoperability
with current WebKit and Blink behaviour, making fragment parsing break
out of foreign content in the same way document parsing does.

Before this code change, when parsing elements like <p>, <div>, and
<nobr> inside SVG/MathML via innerHTML, they would stay in the foreign
namespace. But, with this change, they now correctly “break out”, and
are created in the HTML namespace.

TreeBuilder.java
----------------
  - Start tags: Remove fragment-only restriction on break-out behavior
  - End tags: Allow </p> and </br> to reach mode-handling-in-fragment case
  - Use currentPtr > 0 to preserve context element when popping
@sideshowbarker sideshowbarker force-pushed the sideshowbarker/fragment-parsing-in-foreign-content branch from 43928ea to 0e04831 Compare December 30, 2025 08:58
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.

3 participants