-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Self-closing tag on void elements shouldn't be a parse error/warning in Dom\HTMLParser #17485
Comments
@lexborisov should I have opened this in your repo? |
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
|
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. |
After reading the spec sheet again, if (!is_void) { |
This is how I read it too, but assumed it was too simple of a fix. |
I also think the check should probably be negated. |
Fixed in lexbor/lexbor@e39083b and lexbor/lexbor@ae97abf |
Per report from Pavel Djundik. This related #17485 issue on GitHub.
@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. |
Just to add about svgs (before the fix at least), I've noticed that |
@xPaw that is at least consistent with my browser. Try this JS: html = `<!DOCTYPE html>
<html>
<body>
<svg width="100" height="100">
<path />
</svg>
</body>
</html>`;
dom = (new DOMParser).parseFromString(html, 'text/html');
dom.body.innerHTML |
I figured it out, void elements are only checked in the HTML namespace, in other cases it's always false. https://html.spec.whatwg.org/multipage/syntax.html#elements-2 |
@lexborisov Do you mean this?
|
But then it is not quite clear why the specification requires to call acknowledge-self-closing-flag for Otherwise |
Seems like acknowledge disables the error:
|
It seems to be, but it would seem that it will always be false for |
The spec is kind of all over the place, but this would imply that it gets set to true during tag name parse:
|
Description
The following code:
Resulted in this output:
I believe the html standard specifically allows this on void elements: ref
it doesn't warn for tags like
<div />
and simply opens it as normal.relevant code:
php-src/ext/dom/lexbor/lexbor/html/tree.h
Lines 334 to 339 in 5c39a46
PHP Version
8.4.3
Operating System
No response
The text was updated successfully, but these errors were encountered: