From c4ff251f13517ffb3f41580a60dacf746539bbba Mon Sep 17 00:00:00 2001 From: dmsnell Date: Sat, 18 May 2024 18:22:14 +0000 Subject: [PATCH] Move is_utf8_charset() into functions.php This caused issues in maintenance mode, and it's not warranted to have its own module. This will live alongside `_canonical_charset()`, it's partner function. Fixes: #61182. Props: dmsnell, sergeybiryukov, swisspiddy. Follow-up to: [58148]. Built from https://develop.svn.wordpress.org/trunk@58169 git-svn-id: http://core.svn.wordpress.org/trunk@57632 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 43 +++++++++++++++++++++++++++++++++ wp-includes/unicode.php | 51 --------------------------------------- wp-includes/version.php | 2 +- wp-settings.php | 1 - 4 files changed, 44 insertions(+), 53 deletions(-) delete mode 100644 wp-includes/unicode.php diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3634190663..2b2e3379c7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -7465,6 +7465,49 @@ function get_tag_regex( $tag ) { return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) ); } +/** + * Indicates if a given slug for a character set represents the UTF-8 + * text encoding. If not provided, examines the current blog's charset. + * + * A charset is considered to represent UTF-8 if it is a case-insensitive + * match of "UTF-8" with or without the hyphen. + * + * Example: + * + * true === is_utf8_charset( 'UTF-8' ); + * true === is_utf8_charset( 'utf8' ); + * false === is_utf8_charset( 'latin1' ); + * false === is_utf8_charset( 'UTF 8' ); + * + * // Only strings match. + * false === is_utf8_charset( [ 'charset' => 'utf-8' ] ); + * + * // Without a given charset, it depends on the site option "blog_charset". + * $is_utf8 = is_utf8_charset(); + * + * @since 6.6.0 + * + * @param ?string $blog_charset Slug representing a text character encoding, or "charset". + * E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". + * @return bool Whether the slug represents the UTF-8 encoding. + */ +function is_utf8_charset( $blog_charset = null ) { + $charset_to_examine = $blog_charset ?? get_option( 'blog_charset' ); + + /* + * Only valid string values count: the absence of a charset + * does not imply any charset, let alone UTF-8. + */ + if ( ! is_string( $charset_to_examine ) ) { + return false; + } + + return ( + 0 === strcasecmp( 'UTF-8', $charset_to_examine ) || + 0 === strcasecmp( 'UTF8', $charset_to_examine ) + ); +} + /** * Retrieves a canonical form of the provided charset appropriate for passing to PHP * functions such as htmlspecialchars() and charset HTML attributes. diff --git a/wp-includes/unicode.php b/wp-includes/unicode.php deleted file mode 100644 index 5348e49789..0000000000 --- a/wp-includes/unicode.php +++ /dev/null @@ -1,51 +0,0 @@ - 'utf-8' ] ); - * - * // Without a given charset, it depends on the site option "blog_charset". - * $is_utf8 = is_utf8_charset(); - * - * @since 6.6.0 - * - * @param ?string $blog_charset Slug representing a text character encoding, or "charset". - * E.g. "UTF-8", "Windows-1252", "ISO-8859-1", "SJIS". - * @return bool Whether the slug represents the UTF-8 encoding. - */ -function is_utf8_charset( $blog_charset = null ) { - $charset_to_examine = $blog_charset ?? get_option( 'blog_charset' ); - - /* - * Only valid string values count: the absence of a charset - * does not imply any charset, let alone UTF-8. - */ - if ( ! is_string( $charset_to_examine ) ) { - return false; - } - - return ( - 0 === strcasecmp( 'UTF-8', $charset_to_examine ) || - 0 === strcasecmp( 'UTF8', $charset_to_examine ) - ); -} diff --git a/wp-includes/version.php b/wp-includes/version.php index 3dd43edc41..1215c806b4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58168'; +$wp_version = '6.6-alpha-58169'; /** * 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 4d8a35ae83..9673479bfa 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -106,7 +106,6 @@ 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';