Skip to content

Self-closing tag on void elements shouldn't be a parse error/warning in \Dom\HTMLDocument #17485

Closed
@xPaw

Description

@xPaw

Description

The following code:

<?php
$Data = "<!DOCTYPE HTML>\n<br />\n<input />";
$Document = \Dom\HTMLDocument::createFromString( $Data );
echo $Document->saveHTML();

Resulted in this output:

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.

relevant code:

bool is_void = lxb_html_tag_is_void(token->tag_id);
if (is_void) {
lxb_html_tree_parse_error(tree, token,
LXB_HTML_RULES_ERROR_NOVOHTELSTTAWITRSO);
}

PHP Version

8.4.3

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions