Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
ivopetkov committed Aug 21, 2016
1 parent faaf075 commit 06bb7c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/HTML5DOMElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ private function updateResult($value)
$matches = [];
preg_match_all('/html5-dom-document-internal-entity1-(.*?)-end/', $value, $matches);
foreach ($matches[0] as $i => $match) {
$value = str_replace($match, '&' . $matches[1][$i] . ';', $value);
$value = str_replace($match, html_entity_decode('&' . $matches[1][$i] . ';'), $value);
}
$matches = [];
preg_match_all('/html5-dom-document-internal-entity2-(.*?)-end/', $value, $matches);
foreach ($matches[0] as $i => $match) {
$value = str_replace($match, '&#' . $matches[1][$i] . ';', $value);
$value = str_replace($match, html_entity_decode('&#' . $matches[1][$i] . ';'), $value);
}
return $value;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public function testHtmlEntities()
$dom = new HTML5DOMDocument();
$dom->loadHTML($bodyContent);
$this->assertTrue($expectedSource === $dom->saveHTML());
$this->assertTrue(html_entity_decode($attributeContent) === $dom->querySelector('div')->getAttribute('data-value'));
$dom->querySelector('div')->setAttribute('data-value', $attributeContent);
$this->assertTrue($attributeContent === $dom->querySelector('div')->getAttribute('data-value'));
}

Expand Down Expand Up @@ -304,14 +306,15 @@ public function testGetAttributes()
{

$dataAttributeValue = '&quot;<>&*;';
$expectedDataAttributeValue = '"<>&*;';
$dom = new HTML5DOMDocument();
$dom->loadHTML('<html><body>'
. '<div class="text1" data-value="' . $dataAttributeValue . '">text1</div>'
. '</body></html>');

$this->assertTrue($dom->querySelector('div')->getAttribute('class') === 'text1');
$this->assertTrue($dom->querySelector('div')->getAttribute('unknown') === '');
$this->assertTrue($dom->querySelector('div')->getAttribute('data-value') === $dataAttributeValue);
$this->assertTrue($dom->querySelector('div')->getAttribute('data-value') === $expectedDataAttributeValue);
$attributes = $dom->querySelector('div')->getAttributes();
$this->assertTrue(sizeof($attributes) === 2);
$this->assertTrue($attributes['class'] === 'text1');
Expand Down

0 comments on commit 06bb7c3

Please sign in to comment.