Directory

Quick-fix: Normalize UTF-8 charset slug detection. · WordPress/WordPress@06a25ca · GitHub
Skip to content

Commit

Permalink
Quick-fix: Normalize UTF-8 charset slug detection.
Browse files Browse the repository at this point in the history
In the merge of [58417] the new file was missed. This commit adds the missing required file.

Developed in WordPress/wordpress-develop#6535
Discussed in https://core.trac.wordpress.org/ticket/61182

Fixes #61182.
Follow-up to [58147].
Props dmsnell, jonsurrell.

Built from https://develop.svn.wordpress.org/trunk@58148


git-svn-id: http://core.svn.wordpress.org/trunk@57613 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
dmsnell committed May 14, 2024
1 parent d30cd41 commit 06a25ca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions wp-includes/unicode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* WordPress API providing Unicode-relevant utilities.
*
* @since 6.6.0
*
* @package WordPress
*/

/**
* 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 )
);
}
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58147';
$wp_version = '6.6-alpha-58148';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 06a25ca

Please sign in to comment.