Masterminds / Masterminds/html5-php

Ignore invalid HTML (or self closed tags)

Open
#251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
1.8k
Forks
122
PR merge metrics
No merged PRs in 30d

Description

Up to version 2.2.0, the following HTML code will be fully parsed

<H1>Heading 1</h1>
<p>Paragraph
<b>Second</b> line.</p>
<ul><li>List item 1</li><li>List item 2<ul><li>List item 2.1</li><li>List item 2.2</li></ul></li><li>List item 3</ul>
<p>Paragraph 2</p>
<h2>Heading 2</h2>
<p>Paragraph 3</p>
<p><img alt="image" width="100" height="20"></p>
<audio />
<video />
<p><a data-rel="attachment">attachment</a></p>
<p>Another paragraph. <a href="http://url.to.link">Hyperlink</a>.</p>
<ol><li>List item 1</li><li>List item 2<ol><li>List item 2.1</li><li>List item 2.2</li></ol></li><li>List item 3</ol>

In more recent versions, it stops parsing at the tag <audio /> (if I change to be <audio></audio>, it works), but no errors are generated (->hasErrors() returns false).

Is this behaviour intentional? and is there a way in more recent version to replicate what happens in version 2.2.0 or below?

For the HTML shared above, here is the code I'm running

$html5 = new HTML5();
$html5->loadHTMLFragment($html);
foreach ($fragment->childNodes as $child) {
        echo $child->nodeName . "\n";
 }

And the respective output in version 2.9.0:

h1
#text
p
#text
ul
#text
p
#text
h2
#text
p
#text
p
#text
audio

but for version 2.2.0, I get

h1
#text
p
#text
ul
#text
p
#text
h2
#text
p
#text
p
#text
audio
#text
video
#text
p
#text
p
#text
ol

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the HTML5::loadHTMLFragment entry point and reproduce the supplied fragment, especially the self-closed audio and video tags. Compare the child-node output and hasErrors() behavior described for versions 2.9.0 and 2.2.0. Done means the intended handling of these tags is established and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, php
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.