From a4e1b828442ee99369afaaaa5e06179297127b7c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 17 Nov 2026 11:16:11 +0400 Subject: [PATCH] Skip UTF-8 decoding of ASCII bytes after an identifier consume_ident_sequence() scans ASCII name bytes with strspn() and then asks consume_ident_start_codepoint() about the byte that stopped the scan. For an ASCII byte such as `,` `:` or a space, that method ran _wp_scan_utf8() and utf8_ord() before returning 0. An ASCII byte other than a letter, `_` or NUL never starts an identifier, so the method returns 0 for it before decoding. Tokenizing a 70 KB stylesheet (a generated global stylesheet with the admin-bar and buttons styles, 15,979 tokens) took 6.2 ms before and 4.9 ms after, best of 10 runs on PHP 8.5. (cherry picked from commit 0dab3d9d24f9233d2da654b7305ae9a3ebc80ba0) --- src/wp-includes/css-api/class-wp-css-token-processor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-includes/css-api/class-wp-css-token-processor.php b/src/wp-includes/css-api/class-wp-css-token-processor.php index e9b0e27e4bd7e..cf6c9ec7cf678 100644 --- a/src/wp-includes/css-api/class-wp-css-token-processor.php +++ b/src/wp-includes/css-api/class-wp-css-token-processor.php @@ -1387,6 +1387,11 @@ private function consume_ident_start_codepoint( $at ): int { return 1; } + // Other ASCII code points do not start an identifier. + if ( $this->css[ $at ] < "\x80" ) { + return 0; + } + $new_at = $at; $invalid_length = 0; if ( 1 !== _wp_scan_utf8( $this->css, $new_at, $invalid_length, null, 1 ) ) {