From 6f0c0a109285553f7d49023cfc3413116d4b57ac Mon Sep 17 00:00:00 2001 From: azaozz Date: Mon, 19 Jan 2009 04:40:12 +0000 Subject: [PATCH] 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 --- wp-includes/formatting.php | 79 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 772c0c56e7..35ddd38ddc 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -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 = 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; + $_quote_style = $quote_style; + + if ( $quote_style === 'double' ) { + $quote_style = ENT_COMPAT; + $_quote_style = ENT_COMPAT; + } elseif ( $quote_style === 'single' ) { + $quote_style = ENT_NOQUOTES; } // 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: - $translation = array_merge( $single, $double, $others ); - $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); - break; - case ENT_COMPAT: - case 'double': - $translation = array_merge( $double, $others ); - $translation_preg = array_merge( $double_preg, $others_preg ); - break; - case '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: - $translation = $others; - $translation_preg = $others_preg; - break; + if ( $quote_style === ENT_QUOTES ) { + $translation = array_merge( $single, $double, $others ); + $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); + } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { + $translation = array_merge( $double, $others ); + $translation_preg = array_merge( $double_preg, $others_preg ); + } elseif ( $quote_style === 'single' ) { + $translation = array_merge( $single, $others ); + $translation_preg = array_merge( $single_preg, $others_preg ); + } elseif ( $quote_style === ENT_NOQUOTES ) { + $translation = $others; + $translation_preg = $others_preg; } // Remove zero padding on numeric entities