diff --git a/wp-admin/options-reading.php b/wp-admin/options-reading.php index 5dd40f37c4..8f3ba83a5f 100644 --- a/wp-admin/options-reading.php +++ b/wp-admin/options-reading.php @@ -64,7 +64,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; 'blog_charset' ) ); } ?> diff --git a/wp-admin/options.php b/wp-admin/options.php index 8510095e24..34b98ae294 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -160,7 +160,7 @@ $allowed_options['privacy'] = array(); $mail_options = array( 'mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass' ); -if ( ! in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ) ) { +if ( ! is_utf8_charset() ) { $allowed_options['reading'][] = 'blog_charset'; } diff --git a/wp-includes/compat.php b/wp-includes/compat.php index b4ef3d2f67..c50fc69a04 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -91,7 +91,7 @@ function _mb_substr( $str, $start, $length = null, $encoding = null ) { * The solution below works only for UTF-8, so in case of a different * charset just use built-in substr(). */ - if ( ! in_array( $encoding, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ) ) { + if ( ! is_utf8_charset( $encoding ) ) { return is_null( $length ) ? substr( $str, $start ) : substr( $str, $start, $length ); } @@ -176,7 +176,7 @@ function _mb_strlen( $str, $encoding = null ) { * The solution below works only for UTF-8, so in case of a different charset * just use built-in strlen(). */ - if ( ! in_array( $encoding, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ) ) { + if ( ! is_utf8_charset( $encoding ) ) { return strlen( $str ); } diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 77c772001c..7c03c484dd 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -960,19 +960,7 @@ function _wp_specialchars( $text, $quote_style = ENT_NOQUOTES, $charset = false, $quote_style = ENT_QUOTES; } - // Store the site charset as a static to avoid multiple calls to wp_load_alloptions(). - if ( ! $charset ) { - static $_charset = null; - if ( ! isset( $_charset ) ) { - $alloptions = wp_load_alloptions(); - $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; - } - $charset = $_charset; - } - - if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ), true ) ) { - $charset = 'UTF-8'; - } + $charset = _canonical_charset( $charset ? $charset : get_option( 'blog_charset' ) ); $_quote_style = $quote_style; @@ -1114,7 +1102,7 @@ function wp_check_invalid_utf8( $text, $strip = false ) { // Store the site charset as a static to avoid multiple calls to get_option(). static $is_utf8 = null; if ( ! isset( $is_utf8 ) ) { - $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true ); + $is_utf8 = is_utf8_charset(); } if ( ! $is_utf8 ) { return $text; diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 0cc4c44ad1..3634190663 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7474,17 +7474,27 @@ function get_tag_regex( $tag ) { * * @see https://core.trac.wordpress.org/ticket/23688 * - * @param string $charset A charset name. + * @param string $charset A charset name, e.g. "UTF-8", "Windows-1252", "SJIS". * @return string The canonical form of the charset. */ function _canonical_charset( $charset ) { - if ( 'utf-8' === strtolower( $charset ) || 'utf8' === strtolower( $charset ) ) { - + if ( is_utf8_charset( $charset ) ) { return 'UTF-8'; } - if ( 'iso-8859-1' === strtolower( $charset ) || 'iso8859-1' === strtolower( $charset ) ) { - + /* + * Normalize the ISO-8859-1 family of languages. + * + * This is not required for htmlspecialchars(), as it properly recognizes all of + * the input character sets that here are transformed into "ISO-8859-1". + * + * @todo Should this entire check be removed since it's not required for the stated purpose? + * @todo Should WordPress transform other potential charset equivalents, such as "latin1"? + */ + if ( + ( 0 === strcasecmp( 'iso-8859-1', $charset ) ) || + ( 0 === strcasecmp( 'iso8859-1', $charset ) ) + ) { return 'ISO-8859-1'; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5263db6a26..418dcc4f9a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58146'; +$wp_version = '6.6-alpha-58147'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 9673479bfa..4d8a35ae83 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -106,6 +106,7 @@ if ( WP_CACHE && apply_filters( 'enable_loading_advanced_cache_dropin', true ) & wp_set_lang_dir(); // Load early WordPress files. +require ABSPATH . WPINC . '/unicode.php'; require ABSPATH . WPINC . '/class-wp-list-util.php'; require ABSPATH . WPINC . '/formatting.php'; require ABSPATH . WPINC . '/meta.php';