mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
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;
|
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()
|
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
|
||||||
if ( !$charset ) {
|
if ( !$charset ) {
|
||||||
static $_charset;
|
static $_charset;
|
||||||
@ -225,29 +232,13 @@ function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false
|
|||||||
$charset = 'UTF-8';
|
$charset = 'UTF-8';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( $quote_style ) {
|
$_quote_style = $quote_style;
|
||||||
case ENT_QUOTES:
|
|
||||||
default:
|
if ( $quote_style === 'double' ) {
|
||||||
$quote_style = ENT_QUOTES;
|
$quote_style = ENT_COMPAT;
|
||||||
$_quote_style = ENT_QUOTES;
|
$_quote_style = ENT_COMPAT;
|
||||||
break;
|
} elseif ( $quote_style === 'single' ) {
|
||||||
case ENT_COMPAT:
|
$quote_style = ENT_NOQUOTES;
|
||||||
case 'double':
|
|
||||||
$quote_style = ENT_COMPAT;
|
|
||||||
$_quote_style = ENT_COMPAT;
|
|
||||||
break;
|
|
||||||
case '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
|
// Handle double encoding ourselves
|
||||||
@ -298,6 +289,13 @@ function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES )
|
|||||||
return $string;
|
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 )
|
// More complete than get_html_translation_table( HTML_SPECIALCHARS )
|
||||||
$single = array( ''' => '\'', ''' => '\'' );
|
$single = array( ''' => '\'', ''' => '\'' );
|
||||||
$single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' );
|
$single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' );
|
||||||
@ -306,29 +304,18 @@ function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES )
|
|||||||
$others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' );
|
$others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' );
|
||||||
$others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' );
|
$others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' );
|
||||||
|
|
||||||
switch ( $quote_style ) {
|
if ( $quote_style === ENT_QUOTES ) {
|
||||||
case ENT_QUOTES:
|
$translation = array_merge( $single, $double, $others );
|
||||||
default:
|
$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
|
||||||
$translation = array_merge( $single, $double, $others );
|
} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
|
||||||
$translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
|
$translation = array_merge( $double, $others );
|
||||||
break;
|
$translation_preg = array_merge( $double_preg, $others_preg );
|
||||||
case ENT_COMPAT:
|
} elseif ( $quote_style === 'single' ) {
|
||||||
case 'double':
|
$translation = array_merge( $single, $others );
|
||||||
$translation = array_merge( $double, $others );
|
$translation_preg = array_merge( $single_preg, $others_preg );
|
||||||
$translation_preg = array_merge( $double_preg, $others_preg );
|
} elseif ( $quote_style === ENT_NOQUOTES ) {
|
||||||
break;
|
$translation = $others;
|
||||||
case 'single':
|
$translation_preg = $others_preg;
|
||||||
$translation = array_merge( $single, $others );
|
|
||||||
$translation_preg = array_merge( $single_preg, $others_preg );
|
|
||||||
break;
|
|
||||||
case ENT_NOQUOTES:
|
|
||||||
case false:
|
|
||||||
case 0:
|
|
||||||
case '':
|
|
||||||
case null:
|
|
||||||
$translation = $others;
|
|
||||||
$translation_preg = $others_preg;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove zero padding on numeric entities
|
// Remove zero padding on numeric entities
|
||||||
|
Loading…
Reference in New Issue
Block a user