ivopetkov / html5-dom-document-php

A better HTML5 parser for PHP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility to pass HTML5DOMDocument::ALLOW_DUPLICATE_IDS to HTML5DOMElement

cmoeke opened this issue · comments

When i try to change the innerHTML of an HTML5DOMElement i get the Exception: "A DOM node with an ID value "1" already exists! Pass the HTML5DOMDocument::ALLOW_DUPLICATE_IDS option to disable this check."

Example:

<?php
require 'vendor/autoload.php';

$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('<!DOCTYPE html>
<html>
<body>
    <dummy id="1">a</dummy>
    <dummy id="2">b</dummy>
    <dummy id="1">c</dummy>
</body>
</html>', \IvoPetkov\HTML5DOMDocument::ALLOW_DUPLICATE_IDS);

$body = $dom->querySelector('body');
$body->innerHTML .= 'd';

echo $dom->saveHTML();

The problem is that \IvoPetkov\HTML5DOMDocument::ALLOW_DUPLICATE_IDS isn't passed to

$tmpDoc->loadHTML('<body>' . $value . '</body>');

at HTML5DOMElement.php Line 100 and HTML5DOMElement.php Line 111.

Any ideas to solve this problem?
Imho the best option would be to add an setter for innerHTML and outerHTML to pass the options.

This was actually a bug in the library (insertHTML() does not throw an error). There should not be such errors when modifying elements too. It's now fixed in v2.2.8.
Thank you for reporting it.

Thanks for fixing it so fast!