Skip to content

[DomCrawler] Double hyphens in an HTML comment trigger a PHP warning #62233

@longwave

Description

@longwave

Symfony version(s) affected

7.4.0-BETA1

Description

Trying to parse an HTML comment that contains a double hyphen results in a PHP warning from DOMDocument::loadXML().

As far as I can tell from the HTML5 spec, double hyphens are allowed inside HTML comments (but not in XML comments).

This only affects PHP 8.4 where the native HTML5 parser is used.

This issue was found via Drupal's test suite where we embed filenames that contain double hyphens in Twig debug comments.

How to reproduce

> new \Symfony\Component\DomCrawler\Crawler('<!-- page--theme-test -->');

   WARNING  DOMDocument::loadXML(): Double hyphen within comment: <!-- page in Entity, line: 2 in vendor/symfony/dom-crawler/Crawler.php on line 1116.

Possible Solution

Silence the warning from DOMDocument::loadXML():

-        $dom->loadXML($htmlContent);
+        @$dom->loadXML($htmlContent);

Additional Context

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