[php-src] Issue #21486: Dom\HTMLDocument parser mangles xml:space attribute
| From: | JKingweb | Date: | Sat, 21 Mar 2026 17:11:20 +0000 |
| Subject: | [php-src] Issue #21486: Dom\HTMLDocument parser mangles xml:space attribute | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251828@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/21486
Author: JKingweb
### Description
The following code:
```php
<?php
$d = @\Dom\HTMLDocument::createFromString("<div></div>");
$e = $d->getElementsByTagName("div")[0];
$e->innerHTML = '<svg xml:space="default" xlink:href="about:blank"
xmlns:foo="barspace"></svg>';
$svg = $d->querySelector("svg");
echo $e->innerHTML."\n";
echo $svg->attributes[0]->localName."
".var_export($svg->attributes[0]->namespaceURI, true)."\n";
```
Resulted in this output:
```
<svg space="default" xlink:href="about:blank"
xmlns:foo="barspace"></svg>
space NULL
```
But I expected this output instead:
```
<svg xml:space="default" xlink:href="about:blank"
xmlns:foo="barspace"></svg>
space 'http://www.w3.org/XML/1998/namespace'
```
Note this case is covered by the test suite here:
https://github.com/html5lib/html5lib-tests/blob/8f43b7ec8c9d02179f5f38e0ea08cb5000fb9c9e/tree-construction/webkit02.dat#L363
### PHP Version
```plain
PHP 8.5.4 (cli) (built: Mar 11 2026 12:09:53) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.4, Copyright (c) Zend Technologies
with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies
```
### Operating System
Arch Linux