-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Remove the inert document from the HTML fragment parsing algorithm #11970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
foolip
wants to merge
2
commits into
main
Choose a base branch
from
foolip/fragment-parser-no-inert-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123842,17 +123842,11 @@ enum <dfn enum>DOMParserSupportedType</dfn> { | |
| <var>html</var>:</p> | ||
|
|
||
| <ol> | ||
| <li><p>Let <var>newChildren</var> be the result of the <span>HTML fragment parsing | ||
| algorithm</span> given <var>contextElement</var>, <var>html</var>, and true.</p></li> | ||
|
|
||
| <li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node | ||
| document</span> is <var>contextElement</var>'s <span>node document</span>.</p></li> | ||
|
|
||
| <li><p>For each <var>node</var> in <var>newChildren</var>, <span | ||
| data-x="concept-node-append">append</span> <var>node</var> to <var>fragment</var>.</p></li> | ||
| <li><p><span data-x="concept-node-remove">Remove</span> all <var>target</var>'s <span | ||
| data-x="concept-tree-child">children</span>, in <span>tree order</span>.</p></li> | ||
|
|
||
| <li><p><span data-x="concept-node-replace-all">Replace all</span> with <var>fragment</var> within | ||
| <var>target</var>.</p></li> | ||
| <li><p>Run the <span>HTML fragment parsing algorithm</span> given <var>target</var>, | ||
| <var>contextElement</var>, <var>html</var>, and true.</p></li> | ||
| </ol> | ||
| </div> | ||
|
|
||
|
|
@@ -123997,25 +123991,17 @@ enum <dfn enum>DOMParserSupportedType</dfn> { | |
| <var>context</var> and a string <var>markup</var>, are:</p> | ||
|
|
||
| <ol> | ||
| <li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node | ||
| document</span> is <var>context</var>'s <span>node document</span>.</p></li> | ||
|
|
||
| <li><p>Let <var>algorithm</var> be the <span>HTML fragment parsing algorithm</span>.</p></li> | ||
|
|
||
| <li><p>If <var>context</var>'s <span>node document</span> is an <span data-x="XML documents">XML | ||
| document</span>, then set <var>algorithm</var> to the <span>XML fragment parsing | ||
| algorithm</span>.</p></li> | ||
|
|
||
| <li><p>Let <var>newChildren</var> be the result of invoking <var>algorithm</var> given | ||
| <var>context</var> and <var>markup</var>.</p></li> | ||
|
|
||
| <li><p>Let <var>fragment</var> be a new <code>DocumentFragment</code> whose <span>node | ||
| document</span> is <var>context</var>'s <span>node document</span>.</p></li> | ||
|
|
||
| <li> | ||
| <p>For each <var>node</var> of <var>newChildren</var>, in <span>tree order</span>: <span | ||
| data-x="concept-node-append">append</span> <var>node</var> to <var>fragment</var>.</p> | ||
|
|
||
| <p class=note>This ensures the <span>node document</span> for the new <span | ||
| data-x="node">nodes</span> is correct.</p> | ||
| </li> | ||
| <li><p>Invoke <var>algorithm</var> given <var>fragment</var>, <var>context</var> and | ||
| <var>markup</var>.</p></li> | ||
|
|
||
| <li><p>Return <var>fragment</var>.</p></li> | ||
| </ol> | ||
|
|
@@ -144509,10 +144495,11 @@ console.assert(container.firstChild instanceof SuperP); | |
| <h3>Parsing HTML fragments</h3> | ||
|
|
||
| <div algorithm> | ||
| <p>The <dfn>HTML fragment parsing algorithm</dfn>, given an <code>Element</code> node <dfn | ||
| data-x="concept-frag-parse-context"><var>context</var></dfn>, string <var>input</var>, and an | ||
| optional boolean <var>allowDeclarativeShadowRoots</var> (default false) is the following steps. | ||
| They return a list of zero or more nodes.</p> | ||
| <p>The <dfn>HTML fragment parsing algorithm</dfn>, given an <code>Element</code> or | ||
| <code>DocumentFragment</code> <var>target</var>, an <code>Element</code> <dfn | ||
| data-x="concept-frag-parse-context"><var>context</var></dfn>, a string <var>input</var>, and an | ||
| optional boolean <var>allowDeclarativeShadowRoots</var> (default false) is the following | ||
| steps. Zero or more nodes are inserted into <var>target</var>.</p> | ||
|
|
||
| <p class="note">Parts marked <dfn>fragment case</dfn> in algorithms in the <span>HTML | ||
| parser</span> section are parts that only occur if the parser was created for the purposes of this | ||
|
|
@@ -144522,22 +144509,13 @@ console.assert(container.firstChild instanceof SuperP); | |
| handling this algorithm, then that is an error in the specification.</p> | ||
|
|
||
| <ol> | ||
| <li><p>Let <var>document</var> be a <code>Document</code> node whose <span | ||
| data-x="concept-document-type">type</span> is "<code data-x="">html</code>".</p></li> | ||
| <li><p>Let <var>parser</var> be a new <span>HTML parser</span> associated with | ||
| <var>context</var>'s <span>node document</span>.</p></li> | ||
|
|
||
| <li><p>If <var data-x="concept-frag-parse-context">context</var>'s <span>node document</span> is | ||
| in <span>quirks mode</span>, then set <var>document</var>'s <span | ||
| data-x="concept-document-mode">mode</span> to "<code data-x="">quirks</code>".</p></li> | ||
| <li><p>Set <var>parser</var>'s TODO target to <var>target</var>.</p></li> | ||
|
|
||
| <li><p>Otherwise, if <var data-x="concept-frag-parse-context">context</var>'s <span>node | ||
| document</span> is in <span>limited-quirks mode</span>, then set <var>document</var>'s <span | ||
| data-x="concept-document-mode">mode</span> to "<code data-x="">limited-quirks</code>".</p></li> | ||
|
|
||
| <li><p>If <var>allowDeclarativeShadowRoots</var> is true, then set <var>document</var>'s <span | ||
| data-x="concept-document-allow-declarative-shadow-roots">allow declarative shadow roots</span> to | ||
| true.</p></li> | ||
|
|
||
| <li><p>Create a new <span>HTML parser</span>, and associate it with <var>document</var>.</p></li> | ||
| <li><p>If <var>allowDeclarativeShadowRoots</var> is true, then set <var>parser</var>'s | ||
| TODO <!-- https://github.com/whatwg/html/pull/11965 --> to true.</p></li> | ||
|
|
||
| <li> | ||
| <p>Set the state of the <span>HTML parser</span>'s <span>tokenization</span> stage as | ||
|
|
@@ -144577,16 +144555,18 @@ console.assert(container.firstChild instanceof SuperP); | |
| transitions.</p> | ||
| </li> | ||
|
|
||
| <li><p>Let <var>root</var> be the result of <span data-x="create an element">creating an | ||
| element</span> given <var>document</var>, "<code data-x="">html</code>", the <span>HTML | ||
| namespace</span>, null, null, false, and <var>context</var>'s <span | ||
| data-x="element-custom-element-registry">custom element registry</span>.</p></li> | ||
| <li><p>Set up the <span>HTML parser</span>'s <span>stack of open elements</span> so that it | ||
| contains just the single node (maybe not element!) <var>target</var>.</p></li> | ||
|
|
||
| <li><p><span data-x="concept-node-append">Append</span> <var>root</var> to | ||
| <var>document</var>.</p></li> | ||
| <!-- | ||
| Chromium puts the DocumentFragment as the first item on the stack of open elements: | ||
| https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/parser/html_tree_builder.cc;l=339-344;drc=f94df6678b9dba1f9faf292374830260cc90ae54 | ||
|
|
||
| <li><p>Set up the <span>HTML parser</span>'s <span>stack of open elements</span> so that it | ||
| contains just the single element <var>root</var>.</p></li> | ||
| So does WebKit: | ||
| https://github.com/WebKit/WebKit/blob/8ffda356226982423d22448a9c656a060773cd73/Source/WebCore/html/parser/HTMLTreeBuilder.cpp#L282-L284 | ||
|
|
||
| What does Gecko do? | ||
| --> | ||
|
|
||
| <li><p>If <var data-x="concept-frag-parse-context">context</var> is a <code>template</code> | ||
| element, then push "<span data-x="insertion mode: in template">in template</span>" onto the | ||
|
|
@@ -144624,9 +144604,6 @@ console.assert(container.firstChild instanceof SuperP); | |
|
|
||
| <li><p>Start the <span>HTML parser</span> and let it run until it has consumed all the characters | ||
| just inserted into the input stream.</p></li> | ||
|
|
||
| <li><p>Return <var>root</var>'s <span data-x="concept-tree-child">children</span>, in <span>tree | ||
| order</span>.</p></li> | ||
| </ol> | ||
| </div> | ||
|
|
||
|
|
@@ -144952,9 +144929,10 @@ console.assert(container.firstChild instanceof SuperP); | |
| <h3 id="parsing-xhtml-fragments">Parsing XML fragments</h3> | ||
|
|
||
| <div algorithm> | ||
| <p>The <dfn>XML fragment parsing algorithm</dfn> given an <code>Element</code> node <var | ||
| <p>The <dfn>XML fragment parsing algorithm</dfn> given an <code>Element</code> or | ||
| <code>DocumentFragment</code> <var>target</var>, <code>Element</code> node <var | ||
| data-x="concept-frag-parse-context">context</var> and a string <var>input</var>, runs the | ||
| following steps. They return a list of nodes.</p> | ||
| following steps. Zero or more nodes are inserted into <var>target</var>.</p> | ||
|
|
||
| <ol> | ||
| <li><p>Create a new <span>XML parser</span>.</p></li> | ||
|
|
@@ -144989,8 +144967,9 @@ console.assert(container.firstChild instanceof SuperP); | |
| <!-- This is technically redundant, but apparently it has gone wrong in the past: | ||
| https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1443 --> | ||
|
|
||
| <li><p>Return the resulting <code>Document</code> node's <span>document element</span>'s <span | ||
| data-x="concept-tree-child">children</span>, in <span>tree order</span>.</p></li> | ||
| <li><p><span data-x="concept-node-append">Append</span> the resulting <code>Document</code> | ||
| node's <span>document element</span>'s <span data-x="concept-tree-child">children</span> to | ||
| <var>target</var>, in <span>tree order</span>.</p></li> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will create the wrong mutation records. |
||
| </ol> | ||
| </div> | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong as this would mean the parser will potentially manipulate that document. Though exactly how this is layered today is unclear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the bits that I could find beyond inserting nodes:
I'll have to check how implementations deal with these cases.