Browse Source

Correct error in tst harness related to comments

ns
J. King 3 years ago
parent
commit
d35e4f909e
  1. 11
      lib/TreeBuilder.php
  2. 8
      tests/cases/TestTreeConstructor.php

11
lib/TreeBuilder.php

@ -326,8 +326,8 @@ class TreeBuilder {
# A comment token
elseif ($token instanceof CommentToken) {
# Insert a comment as the last child of the Document object.
// DEVIATION: PHP's DOM cannot have comments before the DOCTYPE, so just going
// to ignore them instead.
// DEVIATION: PHP's DOM does not allow comments as children of the document
// and silently drops them, so this is actually a no-op
$this->insertCommentToken($token, $this->DOM);
}
# A DOCTYPE token
@ -1854,7 +1854,12 @@ class TreeBuilder {
# 3. Create a Comment node whose data attribute is set to data and whose node
# document is the same as that of the node in which the adjusted insertion
# location finds itself.
$commentNode = $adjustedInsertionLocation->ownerDocument->createComment($token->data);
if ($adjustedInsertionLocation instanceof \DOMDocument) {
$nodeDocument = $adjustedInsertionLocation;
} else {
$nodeDocument = $adjustedInsertionLocation->ownerDocument;
}
$commentNode = $nodeDocument->createComment($token->data);
# 4. Insert the newly created node at the adjusted insertion location.
if ($insertBefore === false) {

8
tests/cases/TestTreeConstructor.php

@ -124,12 +124,12 @@ class TestTreeConstructor extends \PHPUnit\Framework\TestCase {
public function serializeNode(\DOMNode $n): void {
if ($n instanceof \DOMElement) {
$this->serializeElement($n);
} elseif ($n instanceof \DOMCharacterData) {
$this->push('"'.$n->data.'"');
} elseif ($n instanceof \DOMComment) {
$this->push("<!-- ".$n->data." -->");
} elseif ($n instanceof \DOMProcessingInstruction) {
$this->push("<?".$n->target." ".$n->data.">");
} elseif ($n instanceof \DOMComment) {
$this->push("<!-- ".$n->data." -->");
} elseif ($n instanceof \DOMCharacterData) {
$this->push('"'.$n->data.'"');
} else {
throw new \Exception("Node type ".get_class($n)." not handled");
}

Loading…
Cancel
Save