Since PHP 5.2.3, the `htmlspecialchars()` function has an optional `$double_encode` parameter, which we can now use. This will save us a few expensive kses/html decoding calls.

Adds unit tests.

Props miqrogroove.
Fixes #17780.

Built from https://develop.svn.wordpress.org/trunk@32850


git-svn-id: http://core.svn.wordpress.org/trunk@32821 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-06-18 22:00:26 +00:00
parent f632756f16
commit d8c93a081d
2 changed files with 2 additions and 19 deletions

View File

@ -688,24 +688,7 @@ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = fals
$quote_style = ENT_NOQUOTES;
}
// Handle double encoding ourselves
if ( $double_encode ) {
$string = @htmlspecialchars( $string, $quote_style, $charset );
} else {
// Decode & into &
$string = wp_specialchars_decode( $string, $_quote_style );
// Guarantee every &entity; is valid or re-encode the &
$string = wp_kses_normalize_entities( $string );
// Now re-encode everything except &entity;
$string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
$string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
}
$string = implode( '', $string );
}
$string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
// Backwards compatibility
if ( 'single' === $_quote_style )

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32849';
$wp_version = '4.3-alpha-32850';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.