Browse Source

Fixed yet another xmlns issue...

domparser
Dustin Wilson 2 years ago
parent
commit
afaf10d602
  1. 8
      lib/Parser/AttributeSetter.php
  2. 4
      tests/cases/TestTreeConstructor.php
  3. 10
      tests/cases/tree-construction/mensbeam03.dat

8
lib/Parser/AttributeSetter.php

@ -42,6 +42,14 @@ trait AttributeSetter {
$element->setAttributeNS($namespaceURI, $qualifiedName, $value);
$this->mangledAttributes = true;
}
} elseif ($namespaceURI === null && $qualifiedName === 'xmlns') {
// There are even more bugs with xmlns attributes. Xmlns attributes on html
// elements are parsed in the null namespace per the specification. PHP still
// goes a bit screwy when trying to access them afterwards. Attempt to work
// around that.
$a = $element->ownerDocument->createAttribute('xmlns');
$a->value = $value;
$element->setAttributeNode($a);
} else {
try {
$element->setAttribute($qualifiedName, $value);

4
tests/cases/TestTreeConstructor.php

@ -15,7 +15,7 @@ use MensBeam\HTML\Parser\TemplateInsertionModesStack;
use MensBeam\HTML\Parser\Tokenizer;
use MensBeam\HTML\Parser\TreeConstructor;
/**
/**
* @covers \MensBeam\HTML\Parser\Data
* @covers \MensBeam\HTML\Parser\Tokenizer
* @covers \MensBeam\HTML\Parser\TreeConstructor
@ -128,6 +128,8 @@ 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/mensbeam03.dat

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