Fix incorrect quote style in wp_specialchars, props sambauers, see #8767
git-svn-id: http://svn.automattic.com/wordpress/trunk@10376 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fd6f6fe44b
commit
6f0c0a1092
|
@ -212,6 +212,13 @@ function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false
|
|||
return $string;
|
||||
}
|
||||
|
||||
// Account for the previous behaviour of the function when the $quote_style is not an accepted value
|
||||
if ( empty( $quote_style ) ) {
|
||||
$quote_style = ENT_NOQUOTES;
|
||||
} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
|
||||
$quote_style = ENT_QUOTES;
|
||||
}
|
||||
|
||||
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
|
||||
if ( !$charset ) {
|
||||
static $_charset;
|
||||
|
@ -225,29 +232,13 @@ function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false
|
|||
$charset = 'UTF-8';
|
||||
}
|
||||
|
||||
switch ( $quote_style ) {
|
||||
case ENT_QUOTES:
|
||||
default:
|
||||
$quote_style = ENT_QUOTES;
|
||||
$_quote_style = ENT_QUOTES;
|
||||
break;
|
||||
case ENT_COMPAT:
|
||||
case 'double':
|
||||
$_quote_style = $quote_style;
|
||||
|
||||
if ( $quote_style === 'double' ) {
|
||||
$quote_style = ENT_COMPAT;
|
||||
$_quote_style = ENT_COMPAT;
|
||||
break;
|
||||
case 'single':
|
||||
} elseif ( $quote_style === 'single' ) {
|
||||
$quote_style = ENT_NOQUOTES;
|
||||
$_quote_style = 'single';
|
||||
break;
|
||||
case ENT_NOQUOTES:
|
||||
case false:
|
||||
case 0:
|
||||
case '':
|
||||
case null:
|
||||
$quote_style = ENT_NOQUOTES;
|
||||
$_quote_style = ENT_NOQUOTES;
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle double encoding ourselves
|
||||
|
@ -298,6 +289,13 @@ function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES )
|
|||
return $string;
|
||||
}
|
||||
|
||||
// Match the previous behaviour of wp_specialchars() when the $quote_style is not an accepted value
|
||||
if ( empty( $quote_style ) ) {
|
||||
$quote_style = ENT_NOQUOTES;
|
||||
} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
|
||||
$quote_style = ENT_QUOTES;
|
||||
}
|
||||
|
||||
// More complete than get_html_translation_table( HTML_SPECIALCHARS )
|
||||
$single = array( ''' => '\'', ''' => '\'' );
|
||||
$single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' );
|
||||
|
@ -306,29 +304,18 @@ function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES )
|
|||
$others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' );
|
||||
$others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' );
|
||||
|
||||
switch ( $quote_style ) {
|
||||
case ENT_QUOTES:
|
||||
default:
|
||||
if ( $quote_style === ENT_QUOTES ) {
|
||||
$translation = array_merge( $single, $double, $others );
|
||||
$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
|
||||
break;
|
||||
case ENT_COMPAT:
|
||||
case 'double':
|
||||
} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
|
||||
$translation = array_merge( $double, $others );
|
||||
$translation_preg = array_merge( $double_preg, $others_preg );
|
||||
break;
|
||||
case 'single':
|
||||
} elseif ( $quote_style === 'single' ) {
|
||||
$translation = array_merge( $single, $others );
|
||||
$translation_preg = array_merge( $single_preg, $others_preg );
|
||||
break;
|
||||
case ENT_NOQUOTES:
|
||||
case false:
|
||||
case 0:
|
||||
case '':
|
||||
case null:
|
||||
} elseif ( $quote_style === ENT_NOQUOTES ) {
|
||||
$translation = $others;
|
||||
$translation_preg = $others_preg;
|
||||
break;
|
||||
}
|
||||
|
||||
// Remove zero padding on numeric entities
|
||||
|
|
Loading…
Reference in New Issue