0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-18 18:25:18 +00:00

Add tests for new entity decoding codepath.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
This commit is contained in:
Edward Z. Yang 2017-03-12 20:05:09 -07:00
parent 98984546d4
commit 5bc7c72608
3 changed files with 16 additions and 2 deletions

1
NEWS
View File

@ -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

View File

@ -119,9 +119,9 @@ class HTMLPurifier_EntityParser
$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) {

View File

@ -16,8 +16,12 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
$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();
@ -71,6 +75,11 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
$expect,
'Identical expectation [Hex: '. dechex($arg[0]) .']'
);
$this->assertIdentical(
$this->EntityParser->substituteTextEntities($string),
$expect,
'Identical expectation [Hex: '. dechex($arg[0]) .']'
);
}
}
@ -81,6 +90,10 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
"'",
$this->EntityParser->substituteSpecialEntities('&#39;')
);
$this->assertIdentical(
"'",
$this->EntityParser->substituteTextEntities('&#39;')
);
}
}