Browse Source

Handle xmlns on HTML elements correctly

The test for when to produce a parse error was not correct previously
domparser 1.2.7
J. King 1 year ago
parent
commit
82b76b192c
  1. 4
      lib/Parser/TreeConstructor.php
  2. 2
      tests/cases/TestTreeConstructor.php

4
lib/Parser/TreeConstructor.php

@ -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);

2
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])) {

Loading…
Cancel
Save