Skip to content

Commit

Permalink
Add failing test for mutating DOMDocument
Browse files Browse the repository at this point in the history
A DOMDocument instance being passed to the parser should not have
changed after parsing. This could potentially trip-up further use of
the same DOMDocument instance.

See microformats#174.
  • Loading branch information
Zegnat committed May 27, 2018
1 parent ae49928 commit d2a32e3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/Mf2/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,5 +790,27 @@ public function testHtml5OptionalPEndTag() {
$this->assertEquals('Name', $output['items'][0]['properties']['name'][0]);
}

/**
* Make sure the parser does not mutate any DOMDocument instances passed to the constructor.
* @see https://github.com/indieweb/php-mf2/issues/174
* @see https://github.com/microformats/mf2py/issues/104
*/
public function testNotMutatingPassedInDOM() {
$input = file_get_contents(__DIR__ . '/snarfed.org.html');

// Use same parsing as Parser::__construct(), twice to have a comparison object.
libxml_use_internal_errors(true);
$refDoc = new \DOMDocument();
@$refDoc->loadHTML(Mf2\unicodeToHtmlEntities($input));
$inputDoc = new \DOMDocument();
@$inputDoc->loadHTML(Mf2\unicodeToHtmlEntities($input));

// For completion sake, test PHP itself.
$this->assertEquals($refDoc, $inputDoc, 'PHP could not create identical DOMDocument instances.');

// Parse one DOMDocument instance, and test if it is still the same as the other.
Mf2\parse($inputDoc, 'http://snarfed.org/2013-10-23_oauth-dropins');
$this->assertEquals($refDoc, $inputDoc, 'Parsing mutated the DOMDocument.');
}
}

0 comments on commit d2a32e3

Please sign in to comment.