Commit 74ed85d075 for wordpress.org
commit 74ed85d075a88ecdbebc7929b398f320883eccba
Author: westonruter <westonruter@git.wordpress.org>
Date: Wed Nov 25 07:19:52 2026 +0000
Code Quality: Correct by-ref types in UTF-8 compat functions.
In `_wp_scan_utf8()` the `$has_noncharacters` reference was accumulated with the bitwise `|=` operator, which turned the boolean into an integer as soon as a sequence able to encode a noncharacter was scanned, contrary to its documented type. It is now accumulated with a logical OR, so callers always receive a boolean.
New `@param-out` tags document that `$has_noncharacters` and `$found_code_points` are never null on return, even though both accept null when passed in. This empties the `parameterByRef.unusedType` baseline, so it is removed. New tests cover how `_wp_scan_utf8()` counts code points across multibyte sequences and grapheme clusters, how it reports the maximal subparts of invalid byte sequences, and how it detects noncharacters.
Developed in https://github.com/WordPress/wordpress-develop/pull/14025.
Follow-up to r61000, r63022.
Props huzaifaalmesbah, dmsnell, lancewillett, westonruter, rcwpdev.
See #66739.
Built from https://develop.svn.wordpress.org/trunk@65771
git-svn-id: http://core.svn.wordpress.org/trunk@64800 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/compat-utf8.php b/wp-includes/compat-utf8.php
index 326786fe60..924ee4443c 100644
--- a/wp-includes/compat-utf8.php
+++ b/wp-includes/compat-utf8.php
@@ -42,6 +42,7 @@
* @param int|null $max_bytes Stop scanning after this many bytes have been seen.
* @param int|null $max_code_points Stop scanning after this many code points have been seen.
* @param bool|null $has_noncharacters Set to indicate if scanned string contained noncharacters.
+ * @param-out bool $has_noncharacters
* @return int How many code points were successfully scanned.
*/
function _wp_scan_utf8( string $bytes, int &$at, int &$invalid_length, ?int $max_bytes = null, ?int $max_code_points = null, ?bool &$has_noncharacters = null ): int {
@@ -151,7 +152,7 @@ function _wp_scan_utf8( string $bytes, int &$at, int &$invalid_length, ?int $max
// Covers the range U+FDD0–U+FDEF, U+FFFE, U+FFFF.
if ( 0xEF === $b1 ) {
- $has_noncharacters |= (
+ $has_noncharacters = $has_noncharacters || (
( 0xB7 === $b2 && $b3 >= 0x90 && $b3 <= 0xAF ) ||
( 0xBF === $b2 && ( 0xBE === $b3 || 0xBF === $b3 ) )
);
@@ -176,7 +177,7 @@ function _wp_scan_utf8( string $bytes, int &$at, int &$invalid_length, ?int $max
$i += 3;
// Covers U+1FFFE, U+1FFFF, U+2FFFE, U+2FFFF, …, U+10FFFE, U+10FFFF.
- $has_noncharacters |= (
+ $has_noncharacters = $has_noncharacters || (
( 0x0F === ( $b2 & 0x0F ) ) &&
0xBF === $b3 &&
( 0xBE === $b4 || 0xBF === $b4 )
@@ -376,6 +377,7 @@ function _wp_utf8_codepoint_count( string $text, ?int $byte_offset = 0, ?int $ma
* @param ?int $found_code_points Optional. Will be set to number of found code points in
* span, as this might be smaller than the maximum count if
* the string is not long enough.
+ * @param-out int $found_code_points
* @return int Number of bytes spanned by the code points.
*/
function _wp_utf8_codepoint_span( string $text, int $byte_offset, int $max_code_points, ?int &$found_code_points = 0 ): int {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 4eb45524c5..8369c0585a 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.3-alpha-65770';
+$wp_version = '7.3-alpha-65771';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.