Skip to content

Dom\HTMLDocument parser mangles xml:space and xml:lang attributes #21486

Closed

Description

@JKingweb

Description

The following code:

<?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

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

Activity

  1. changed the title [-]Dom\HTMLDocument parser mangles xml:space attribute[/-] [+]Dom\HTMLDocument parser mangles xml:space and xml:lang attributes[/+] on Mar 21, 2026
  2. Oleh8978 commented on Mar 21, 2026

    @Oleh8978

    Reproduced on PHP 8.5.3 (CLI) built via Homebrew on macOS.

    Output:

    space NULL

    Expected xml namespace to be preserved (xml:space with proper namespace URI).

  3. Oleh8978 commented on Mar 21, 2026

    @Oleh8978

    Reproduced on PHP 8.5.3 (CLI) built via Homebrew on macOS.

    Output: space NULL

    Expected xml namespace to be preserved (xml:space with proper namespace URI).

    Reproduced on PHP 8.5.3 (CLI, Homebrew, macOS).

    HTML parsing (Dom\HTMLDocument):

    space NULL

    XML parsing (DOMDocument::loadXML):
    xml:space
    http://www.w3.org/XML/1998/namespace

    This suggests the issue is specific to Dom\HTMLDocument (HTML parsing), where the xml namespace prefix is dropped and namespaceURI is lost.

  4. added a commit that references this issue on Mar 21, 2026
    a759605
  5. added a commit that references this issue on Mar 22, 2026
    c920daa
  6. added 2 commits that reference this issue on Mar 22, 2026
    99365b8
    be539d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions