Masterminds / Masterminds/html5-php

Invalid parsing result when head/body tag is missing

Open
#166 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Consider this:

<html>Hello, This is a test.<br />Does it work this time?</html>

Imo, this is valid HTML and it is also parsed correctly by DOMDocument. However, HTML5 parser will ignore the first line of text. We're using loadHTML() method.

Even this one works with DOMDocument:

Hello, This is a test.<br />Does it work this time?

According to Mozilla documentation:

  • html: The start tag may be omitted if the first thing inside the element is not a comment.
  • body: The start tag may be omitted if the first thing inside it is not a space character, comment, <script> element or <style> element.

Reference: https://github.com/roundcube/roundcubemail/issues/6713#issuecomment-480320339

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 by reproducing the two examples through loadHTML() and compare the HTML5 parser result with DOMDocument. Read the parser path handling omitted html and body start tags, using the linked Mozilla rules as the expected behavior. Done means text before and after the br element is preserved in both examples, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.