From 419fea1a1673cc88fa7ab12d70109c99f123e780 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 25 Jun 2013 19:03:17 +0000 Subject: [PATCH] Normalize the UTF-8 and ISO-8859-1 charset strings stored in blog_charset to make them friendlier with PHP functions that accept a charset such as htmlspecialchars(). fixes #23688 git-svn-id: http://core.svn.wordpress.org/trunk@24510 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 1 + wp-includes/functions.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 4b622a89c5..715b874a16 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -179,6 +179,7 @@ add_filter( 'the_author', 'ent2ncr', 8 ); // Misc filters add_filter( 'option_ping_sites', 'privacy_ping_filter' ); add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop +add_filter( 'option_blog_charset', '_canonical_charset' ); add_filter( 'option_home', '_config_wp_home' ); add_filter( 'option_siteurl', '_config_wp_siteurl' ); add_filter( 'tiny_mce_before_init', '_mce_set_direction' ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index b6739ecf78..15cd8cd47b 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3998,3 +3998,25 @@ function get_tag_regex( $tag ) { return; return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) ); } + +/** + * Return a canonical form of the provided charset appropriate for passing to PHP + * functions such as htmlspecialchars() and charset html attributes. + * + * @link http://core.trac.wordpress.org/ticket/23688 + * @since 3.6.0 + * + * @param string A charset name + * @return string The canonical form of the charset + */ +function _canonical_charset( $charset ) { + if ( 'UTF-8' === $charset || 'utf-8' === $charset || 'utf8' === $charset || + 'UTF8' === $charset ) + return 'UTF-8'; + + if ( 'ISO-8859-1' === $charset || 'iso-8859-1' === $charset || + 'iso8859-1' === $charset || 'ISO8859-1' === $charset ) + return 'ISO-8859-1'; + + return $charset; +} \ No newline at end of file