You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Self-closing tag on void elements shouldn't be a parse error/warning in \Dom\HTMLDocument #17485
Warning: Dom\HTMLDocument::createFromString(): tree error non-void-html-element-start-tag-with-trailing-solidus in Entity, line: 2, column: 2-3 in test.php on line 3
Warning: Dom\HTMLDocument::createFromString(): tree error non-void-html-element-start-tag-with-trailing-solidus in Entity, line: 3, column: 2-6 in test.php on line 3
I believe the html standard specifically allows this on void elements: ref
Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/), which on foreign elements marks the start tag as self-closing. On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.
it doesn't warn for tags like <div /> and simply opens it as normal.
When a start tag token is emitted with its self-closing flag set, if the flag is not acknowledged when it is processed by the tree construction stage, that is a non-void-html-element-start-tag-with-trailing-solidus parse error.
Yeah, it all adds up. I had doubts, because in the code the <param> tag used to be void, but then it was excluded and I didn't notice it, unfortunately.
@lexborisov Thanks a lot! I'm not sure this is entirely correctly fixed however. After cherry-picking your commits into PHP I get a new warning for this line in this test:
@lexborisov Thanks a lot! I'm not sure this is entirely correctly fixed however. After cherry-picking your commits into PHP I get a new warning for this line in this test:
It's a foreign element (in SVG) and I believe it shouldn't warn here based on the spec comments.
I figured it out, void elements are only checked in the HTML namespace, in other cases it's always false.
But I didn't find any direct text about it. It just comes out of the references in the specification.
It seems to be, but it would seem that it will always be false for Foreign elements. What's the point of calling it in then?
Ok, I'll reread the spec sheet again and if anything, I'll contact the folks at WATHWG.
changed the title [-]Self-closing tag on void elements shouldn't be a parse error/warning in Dom\HTMLParser[/-][+]Self-closing tag on void elements shouldn't be a parse error/warning in `\Dom\HTMLDocument`[/+]on Jan 17, 2025
Activity
xPaw commentedon Jan 16, 2025
@lexborisov should I have opened this in your repo?
lexborisov commentedon Jan 16, 2025
@xPaw
It looks like it to me.
This is where you have to look at the tree construction specification. It is written there:
https://html.spec.whatwg.org/multipage/parsing.html#acknowledge-self-closing-flag
xPaw commentedon Jan 16, 2025
Hmm, that seems confusing to me as to what's the correct implementation for a parser. Browsers obviously accept this.
Edit: actually that appears to be correct, since void elements should be acceptable with the slash? Even the error string implies non-void.
lexborisov commentedon Jan 16, 2025
@xPaw
After reading the spec sheet again,
The problem seems to be solved by changing the condition in the code, to negation.
https://github.com/lexbor/lexbor/blob/58c88147db7342aefbc45d5e5621a974c210106a/source/lexbor/html/tree.h#L333
xPaw commentedon Jan 16, 2025
This is how I read it too, but assumed it was too simple of a fix.
ndossche commentedon Jan 16, 2025
I also think the check should probably be negated.
lexborisov commentedon Jan 16, 2025
@xPaw @nielsdos
Yeah, it all adds up. I had doubts, because in the code the
<param>tag used to bevoid, but then it was excluded and I didn't notice it, unfortunately.I'll get the patch ready.
lexborisov commentedon Jan 16, 2025
Fixed in lexbor/lexbor@e39083b and lexbor/lexbor@ae97abf
HTML: fixed error report on self-closing tag parsing.
ndossche commentedon Jan 16, 2025
@lexborisov Thanks a lot! I'm not sure this is entirely correctly fixed however. After cherry-picking your commits into PHP I get a new warning for this line in this test:
php-src/ext/dom/tests/modern/html/interactions/HTMLDocument_getElementsByTagName.phpt
Line 18 in a4fa1e7
It's a foreign element (in SVG) and I believe it shouldn't warn here based on the spec comments.
xPaw commentedon Jan 16, 2025
Just to add about svgs (before the fix at least), I've noticed that
<path />would turn into<path></path>when calling saveHtml.ndossche commentedon Jan 16, 2025
@xPaw that is at least consistent with my browser. Try this JS:
lexborisov commentedon Jan 16, 2025
@nielsdos
I figured it out, void elements are only checked in the HTML namespace, in other cases it's always false.
But I didn't find any direct text about it. It just comes out of the references in the specification.
https://html.spec.whatwg.org/multipage/syntax.html#elements-2
https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign "Any other start tag"
2 remaining items
xPaw commentedon Jan 16, 2025
Seems like acknowledge disables the error:
lexborisov commentedon Jan 16, 2025
It seems to be, but it would seem that it will always be false for
Foreign elements. What's the point of calling it in then?Ok, I'll reread the spec sheet again and if anything, I'll contact the folks at WATHWG.
xPaw commentedon Jan 16, 2025
The spec is kind of all over the place, but this would imply that it gets set to true during tag name parse:
[-]Self-closing tag on void elements shouldn't be a parse error/warning in Dom\HTMLParser[/-][+]Self-closing tag on void elements shouldn't be a parse error/warning in `\Dom\HTMLDocument`[/+]HTML: fixed error report for tokens in foreign content.
lexborisov commentedon Jan 17, 2025
@xPaw @nielsdos
Thanks for help! Fixed in lexbor/lexbor@e58e1e8.
Merge branch 'PHP-8.4'
NEWS for GH-17485
ndossche commentedon Jan 17, 2025
Thanks both, merged into PHP.