From e1975a7d9f408f5f868075f143288fc959cfdc90 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 29 May 2024 15:54:26 +0200 Subject: [PATCH 1/2] Use strcasecmp over strtoupper --- src/wp-includes/class-wp-token-map.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index a932f4cae4d27..114805d0bd1c1 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -579,19 +579,16 @@ public function read_token( $text, $offset = 0, &$matched_token_byte_length = nu * @return string|null Mapped value of lookup key if found, otherwise `null`. */ private function read_small_token( $text, $offset, &$matched_token_byte_length, $case_sensitivity = 'case-sensitive' ) { - $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; - $small_length = strlen( $this->small_words ); - $search_text = substr( $text, $offset, $this->key_length ); - if ( $ignore_case ) { - $search_text = strtoupper( $search_text ); - } + $ignore_case = 'ascii-case-insensitive' === $case_sensitivity; + $small_length = strlen( $this->small_words ); + $search_text = substr( $text, $offset, $this->key_length ); $starting_char = $search_text[0]; $at = 0; while ( $at < $small_length ) { if ( $starting_char !== $this->small_words[ $at ] && - ( ! $ignore_case || strtoupper( $this->small_words[ $at ] ) !== $starting_char ) + ( ! $ignore_case || 0 !== strcasecmp( $this->small_words[ $at ], $starting_char ) ) ) { $at += $this->key_length + 1; continue; @@ -605,7 +602,7 @@ private function read_small_token( $text, $offset, &$matched_token_byte_length, if ( $search_text[ $adjust ] !== $this->small_words[ $at + $adjust ] && - ( ! $ignore_case || strtoupper( $this->small_words[ $at + $adjust ] !== $search_text[ $adjust ] ) ) + ( ! $ignore_case || 0 !== strcasecmp( $this->small_words[ $at + $adjust ], $search_text[ $adjust ] ) ) ) { $at += $this->key_length + 1; continue 2; From 351be8579912908eeebea441b1b5c92ec370209c Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 29 May 2024 16:02:21 +0200 Subject: [PATCH 2/2] Use strcasecmp in HTML decoder --- src/wp-includes/html-api/class-wp-html-decoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-decoder.php b/src/wp-includes/html-api/class-wp-html-decoder.php index 91278cee82083..3178f372a7c0f 100644 --- a/src/wp-includes/html-api/class-wp-html-decoder.php +++ b/src/wp-includes/html-api/class-wp-html-decoder.php @@ -39,7 +39,7 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen while ( $search_at < $search_length && $haystack_at < $haystack_end ) { $chars_match = $loose_case - ? strtolower( $haystack[ $haystack_at ] ) === strtolower( $search_text[ $search_at ] ) + ? 0 === strcasecmp( $haystack[ $haystack_at ], $search_text[ $search_at ] ) : $haystack[ $haystack_at ] === $search_text[ $search_at ]; $is_introducer = '&' === $haystack[ $haystack_at ];