diff --git a/lib/Parser/TreeConstructor.php b/lib/Parser/TreeConstructor.php index 119e736..d9ff94e 100644 --- a/lib/Parser/TreeConstructor.php +++ b/lib/Parser/TreeConstructor.php @@ -3541,7 +3541,7 @@ class TreeConstructor { # corresponding cell in the fourth column. (This fixes the use of namespaced # attributes, in particular lang attributes in the XML namespace.) // DOMElement::setAttributeNS requires the prefix and local name be in one - // string, so there is no need to separate the prefix and the local name here. + // string, so there is no need to separate the prefix and the local name here. $a->namespace = self::FOREIGN_ATTRIBUTE_NAMESPACE_MAP[$a->name] ?? null; } # Insert a foreign element for the token, in the same namespace as the adjusted @@ -4236,9 +4236,9 @@ class TreeConstructor { // NOTE: The specification is silent as to how to handle these // attributes. We assume these bad attributes should be dropped, // since they break the DOM when added - if ($attr->name === "xmlns" && $namespace !== $this->htmlNamespace && $attr->value !== $namespace) { + if ($attr->name === "xmlns" && $attr->namespace === Parser::XMLNS_NAMESPACE && $attr->value !== ($namespace ?? Parser::HTML_NAMESPACE)) { $this->error(ParseError::INVALID_NAMESPACE_ATTRIBUTE_VALUE, "xmlns", $namespace); - } elseif ($attr->name === "xmlns:xlink" && $namespace !== $this->htmlNamespace && $attr->value !== Parser::XLINK_NAMESPACE) { + } elseif ($attr->name === "xmlns:xlink" && $attr->namespace === Parser::XMLNS_NAMESPACE && $attr->value !== Parser::XLINK_NAMESPACE) { $this->error(ParseError::INVALID_NAMESPACE_ATTRIBUTE_VALUE, "xmlns:xlink", Parser::XLINK_NAMESPACE); } else { $this->elementSetAttribute($element, $attr->namespace, $attr->name, $attr->value); diff --git a/tests/cases/TestTreeConstructor.php b/tests/cases/TestTreeConstructor.php index d22f933..9e8179a 100644 --- a/tests/cases/TestTreeConstructor.php +++ b/tests/cases/TestTreeConstructor.php @@ -135,7 +135,7 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase { } protected function patchTest(string $data, $fragment, array $errors, array $exp): array { - // When using the HTML namespace, xmlns attributes lose their namespace due to a PHP limitation + // When using the HTML namespace, xmlns attributes in the xmlns namespace lose their namespace URI due to a PHP limitation if ($this->ns) { for ($a = 0; $a < sizeof($exp); $a++) { if (preg_match('/^\|\s+xmlns xmlns=/', $exp[$a])) {