Browse Source

Commit more fixes

Some remaining failures are due to spec/test changes
ns
J. King 3 years ago
parent
commit
4f2219edb7
  1. 6
      lib/Parser/TreeBuilder.php
  2. 7
      tests/cases/TestTreeConstructor.php

6
lib/Parser/TreeBuilder.php

@ -4195,17 +4195,13 @@ class TreeBuilder {
# Let local name be the tag name of the token.
# Let element be the result of creating an element given document,
# localName, given namespace, null, and is.
if ($token->name === "svg" && $namespace !== Parser::SVG_NAMESPACE) {
//var_export($namespace);
//exit;
}
try {
$element = $this->DOM->createElementNS($namespace, $token->name);
} catch (\DOMException $e) {
// The element name is invalid for XML
// Replace any offending characters with "UHHHHHH" where H are the
// uppercase hexadecimal digits of the character's code point
if ($namespace !== null) {
if ($namespace !== $this->htmlNamespace) {
$qualifiedName = implode(":", array_map([$this, "coerceName"], explode(":", $token->name, 2)));
} else {
$qualifiedName = $this->coerceName($token->name);

7
tests/cases/TestTreeConstructor.php

@ -35,7 +35,7 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
protected $ns;
/** @dataProvider provideStandardTreeTests */
public function xtestStandardTreeTests(string $data, array $exp, array $errors, $fragment): void {
public function testStandardTreeTests(string $data, array $exp, array $errors, $fragment): void {
$this->runTreeTest($data, $exp, $errors, $fragment, null);
}
@ -82,7 +82,8 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
$fragment = explode(" ", $fragment);
assert(sizeof($fragment) < 3);
if (sizeof($fragment) === 1) {
$fragmentContext = $doc->createElement($fragment[0]);
// an HTML element
$fragmentContext = $doc->createElementNS($htmlNamespace, $fragment[0]);
} else {
$ns = array_flip(Parser::NAMESPACE_MAP)[$fragment[0]] ?? null;
assert(isset($ns));
@ -362,7 +363,7 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
$prefix = Parser::NAMESPACE_MAP[$e->namespaceURI];
assert((bool) $prefix, new \Exception("Prefix for namespace {$e->namespaceURI} is not defined"));
$prefix .= " ";
if ($this->ns) {
if ($this->ns && $prefix === "html ") {
// if the parser is using the HTML namespace on purpose, the prefix should be omitted
$prefix = "";
}

Loading…
Cancel
Save