Fix using `htmlspecialchars()` whit the `$double_encode` parameter. PHP < 5.4 doesn't validate the entities.

Props miqrogroove. Fixes #17780.

git-svn-id: https://develop.svn.wordpress.org/trunk@32851 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-06-19 01:52:48 +00:00
parent 4d8c4295f3
commit 5cb9a4b019
3 changed files with 8 additions and 2 deletions

View File

@ -688,6 +688,12 @@ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = fals
$quote_style = ENT_NOQUOTES;
}
if ( ! $double_encode ) {
// Guarantee every &entity; is valid, convert &garbage; into &amp;garbage;
// This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable.
$string = wp_kses_normalize_entities( $string );
}
$string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
// Backwards compatibility

View File

@ -34,7 +34,7 @@ class Tests_Formatting_EscHtml extends WP_UnitTestCase {
function test_ignores_existing_entities() {
$source = '&#038; &#x00A3; &#x22; &amp;';
$res = '&#038; &#x00A3; &#x22; &amp;';
$res = '&#038; &#xA3; &#x22; &amp;';
$this->assertEquals( $res, esc_html($source) );
}
}

View File

@ -85,7 +85,7 @@ class Tests_Formatting_WPSpecialchars extends WP_UnitTestCase {
return array(
array(
'This & that, this &amp; that, &#8212; &quot; &QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &dollar; &times;',
'This &amp; that, this &amp; that, &#8212; &quot; &amp;QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &amp;dollar; &times;',
'This &amp; that, this &amp; that, &#8212; &quot; &amp;QUOT; &Uacute; &nbsp; &#034; &#034; &#034; &#x22; &#x22; &amp;dollar; &times;',
),
array(
'&& &&amp; &amp;&amp; &amp;;',