Skip to content

Commit

Permalink
Add tests for new entity decoding codepath.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Mar 13, 2017
1 parent 9898454 commit 5bc7c72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier

4.9.2, unknown release date
- Fixes PHP 5.3 compatibility
- Fix breakage when decoding decimal entities. Thanks @rybakit (#129)

4.9.1, released 2017-03-08
! %URI.DefaultScheme can now be set to null, in which case
Expand Down
4 changes: 2 additions & 2 deletions library/HTMLPurifier/EntityParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ protected function entityCallback($matches)
$hex_part = @$matches[1];
$dec_part = @$matches[2];
$named_part = empty($matches[3]) ? @$matches[4] : $matches[3];
if ($hex_part) {
if ($hex_part !== NULL && $hex_part !== "") {
return HTMLPurifier_Encoder::unichr(hexdec($hex_part));
} elseif ($dec_part) {
} elseif ($dec_part !== NULL && $dec_part !== "") {
return HTMLPurifier_Encoder::unichr((int) $dec_part);
} else {
if (!$this->_entity_lookup) {
Expand Down
13 changes: 13 additions & 0 deletions tests/HTMLPurifier/EntityParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public function test_substituteNonSpecialEntities()
$char_theta = $this->_entity_lookup->table['theta'];
$this->assertIdentical($char_theta,
$this->EntityParser->substituteNonSpecialEntities('&theta;') );
$this->assertIdentical($char_theta,
$this->EntityParser->substituteTextEntities('&theta;') );
$this->assertIdentical('"',
$this->EntityParser->substituteNonSpecialEntities('"') );
$this->assertIdentical('"',
$this->EntityParser->substituteTextEntities('"') );

// numeric tests, adapted from Feyd
$args = array();
Expand Down Expand Up @@ -71,6 +75,11 @@ public function test_substituteNonSpecialEntities()
$expect,
'Identical expectation [Hex: '. dechex($arg[0]) .']'
);
$this->assertIdentical(
$this->EntityParser->substituteTextEntities($string),
$expect,
'Identical expectation [Hex: '. dechex($arg[0]) .']'
);
}

}
Expand All @@ -81,6 +90,10 @@ public function test_substituteSpecialEntities()
"'",
$this->EntityParser->substituteSpecialEntities('&#39;')
);
$this->assertIdentical(
"'",
$this->EntityParser->substituteTextEntities('&#39;')
);
}

}
Expand Down

0 comments on commit 5bc7c72

Please sign in to comment.