Browse Source

Fix xmlns on HTML elements when using HTML ns

domparser
J. King 1 year ago
parent
commit
bd43403aa7
  1. 4
      lib/Parser/TreeConstructor.php
  2. 2
      tests/cases/TestTreeConstructor.php
  3. 10
      tests/cases/tree-construction/mensbeam01.dat
  4. 10
      tests/cases/tree-construction/mensbeam03.dat

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 !== null && $attr->value !== $namespace) {
if ($attr->name === "xmlns" && $namespace !== $this->htmlNamespace && $attr->value !== $namespace) {
$this->error(ParseError::INVALID_NAMESPACE_ATTRIBUTE_VALUE, "xmlns", $namespace);
} elseif ($attr->name === "xmlns:xlink" && $namespace !== null && $attr->value !== Parser::XLINK_NAMESPACE) {
} elseif ($attr->name === "xmlns:xlink" && $namespace !== $this->htmlNamespace && $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

@ -140,8 +140,6 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
for ($a = 0; $a < sizeof($exp); $a++) {
if (preg_match('/^\|\s+xmlns xmlns=/', $exp[$a])) {
$exp[$a] = preg_replace('/^\|(\s+)xmlns xmlns=/', "|$1xmlns=", $exp[$a]);
} elseif (preg_match('/^\|\s+xmlns=/', $exp[$a])) {
$this->markTestSkipped();
}
}
}

10
tests/cases/tree-construction/mensbeam01.dat

@ -66,3 +66,13 @@
| xml id="proper"
| <p>
| xml:id="bogus"
#data
<!DOCTYPE html><html xmlns="ook">
#errors
#document
| <!DOCTYPE html>
| <html>
| xmlns="ook"
| <head>
| <body>

10
tests/cases/tree-construction/mensbeam03.dat

@ -143,13 +143,3 @@ table
| <tbody>
| <tr>
| "X"
#data
<!DOCTYPE html><html xmlns="ook">
#errors
#document
| <!DOCTYPE html>
| <html>
| xmlns="ook"
| <head>
| <body>
Loading…
Cancel
Save