Page MenuHomePhabricator

Self-closing HTML tags shouldn't be accepted
Closed, DeclinedPublic


According to the HTML5 spec, normal elements must have a start and end tag, but for some exceptions. Currently Parsoid accepts these tags as valid, as seen in the test: "Handling html with a div self-closing tag" in parserTests.txt:

<div title />
<div title/>
<div title/ >
<div title=bar />
<div title=bar/>
<div title=bar/ >

results in

<div title="" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="" data-parsoid='{"stx":"html","selfClose":true,"brokenHTMLTag":true}'></div>
<div title="bar" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="bar" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="bar/" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></div>

PHP parser renders them as text:

<p>&lt;div title /&gt;
&lt;div title/&gt;
<p>&lt;div title=bar /&gt;
&lt;div title=bar/&gt;
<div title="bar/"></div>

Event Timeline

ssastry raised the priority of this task from to Medium.
ssastry updated the task description. (Show Details)
ssastry added a project: Parsoid.
ssastry changed Security from none to None.
marcoil renamed this task from Self-closing HTML tags are being accepted to Self-closing HTML tags shouldn't be accepted.Dec 29 2014, 5:35 PM
marcoil updated the task description. (Show Details)
ssastry lowered the priority of this task from Medium to Low.Dec 18 2017, 10:21 PM
ssastry subscribed.

Both PHP Parser and Parsoid now render self-closed HTML tags as <tag></tag>. Separately, we have created a high priority linter category to have editors fix up these incorrect uses of self-closing tags.

At some point in the future once Tidy is replaced and this category is sufficiently sparse across all wikis, we'll probably stop accepting them altogether.

This is no longer a Parsoid-specific issue. Whether such invalid tags should parse as text or the way it is rendering now is left for future cleanup discussion.