@@ -23,18 +23,17 @@ class WP_HTML_Decoder {
2323 * true === WP_HTML_Decoder::attribute_starts_with( $value, 'http:', 'ascii-case-insensitive' );
2424 * false === WP_HTML_Decoder::attribute_starts_with( $value, 'https:', 'ascii-case-insensitive' );
2525 *
26- * @param string $haystack String containing the raw non-decoded attribute value.
27- * @param string $search_text Does the attribute value start with this plain string.
28- * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching.
29- * Default 'case-sensitive'.
26+ * @param string $haystack String containing the raw non-decoded attribute value.
27+ * @param string $search_text Does the attribute value start with this plain string.
28+ * @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching.
29+ * Default 'case-sensitive'.
3030 *
3131 * @return bool Whether the attribute value starts with the given string.
3232 * @since 6.6.0
33- *
3433 */
3534 public static function attribute_starts_with ( $ haystack , $ search_text , $ case_sensitivity = 'case-sensitive ' ): bool {
3635 $ search_length = strlen ( $ search_text );
37- $ loose_case = 'ascii-case-insensitive ' === $ case_sensitivity ;
36+ $ loose_case = $ case_sensitivity === 'ascii-case-insensitive ' ;
3837 $ haystack_end = strlen ( $ haystack );
3938 $ search_at = 0 ;
4039 $ haystack_at = 0 ;
@@ -44,25 +43,25 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen
4443 ? strtolower ( $ haystack [ $ haystack_at ] ) === strtolower ( $ search_text [ $ search_at ] )
4544 : $ haystack [ $ haystack_at ] === $ search_text [ $ search_at ];
4645
47- $ is_introducer = ' & ' === $ haystack [ $ haystack_at ];
46+ $ is_introducer = $ haystack [ $ haystack_at ] === ' & ' ;
4847 $ next_chunk = $ is_introducer
4948 ? self ::read_character_reference ( 'attribute ' , $ haystack , $ haystack_at , $ token_length )
5049 : null ;
5150
5251 // If there's no character reference and the characters don't match, the match fails.
53- if ( null === $ next_chunk && ! $ chars_match ) {
52+ if ( $ next_chunk === null && ! $ chars_match ) {
5453 return false ;
5554 }
5655
5756 // If there's no character reference but the character do match, then it could still match.
58- if ( null === $ next_chunk && $ chars_match ) {
59- ++ $ haystack_at ;
60- ++ $ search_at ;
57+ if ( $ next_chunk === null && $ chars_match ) {
58+ ++$ haystack_at ;
59+ ++$ search_at ;
6160 continue ;
6261 }
6362
6463 // If there is a character reference, then the decoded value must exactly match what follows in the search string.
65- if ( 0 !== substr_compare ( $ search_text , $ next_chunk , $ search_at , strlen ( $ next_chunk ), $ loose_case ) ) {
64+ if ( substr_compare ( $ search_text , $ next_chunk , $ search_at , strlen ( $ next_chunk ), $ loose_case ) !== 0 ) {
6665 return false ;
6766 }
6867
@@ -86,11 +85,10 @@ public static function attribute_starts_with( $haystack, $search_text, $case_sen
8685 *
8786 * '“😄”' === WP_HTML_Decode::decode_text_node( '“😄”' );
8887 *
89- * @param string $text Text containing raw and non-decoded text node to decode.
88+ * @param string $text Text containing raw and non-decoded text node to decode.
9089 *
9190 * @return string Decoded UTF-8 value of given text node.
9291 * @since 6.6.0
93- *
9492 */
9593 public static function decode_text_node ( $ text ): string {
9694 return static ::decode ( 'data ' , $ text );
@@ -107,11 +105,10 @@ public static function decode_text_node( $text ): string {
107105 *
108106 * '“😄”' === WP_HTML_Decode::decode_attribute( '“😄”' );
109107 *
110- * @param string $text Text containing raw and non-decoded attribute value to decode.
108+ * @param string $text Text containing raw and non-decoded attribute value to decode.
111109 *
112110 * @return string Decoded UTF-8 value of given attribute value.
113111 * @since 6.6.0
114- *
115112 */
116113 public static function decode_attribute ( $ text ): string {
117114 return static ::decode ( 'attribute ' , $ text );
@@ -128,14 +125,13 @@ public static function decode_attribute( $text ): string {
128125 *
129126 * '©' = WP_HTML_Decoder::decode( 'data', '©' );
130127 *
131- * @param string $context `attribute` for decoding attribute values, `data` otherwise.
132- * @param string $text Text document containing span of text to decode.
128+ * @param string $context `attribute` for decoding attribute values, `data` otherwise.
129+ * @param string $text Text document containing span of text to decode.
133130 *
134131 * @return string Decoded UTF-8 string.
135132 * @since 6.6.0
136133 *
137134 * @access private
138- *
139135 */
140136 public static function decode ( $ context , $ text ): string {
141137 $ decoded = '' ;
@@ -145,24 +141,24 @@ public static function decode( $context, $text ): string {
145141
146142 while ( $ at < $ end ) {
147143 $ next_character_reference_at = strpos ( $ text , '& ' , $ at );
148- if ( false === $ next_character_reference_at ) {
144+ if ( $ next_character_reference_at === false ) {
149145 break ;
150146 }
151147
152148 $ character_reference = self ::read_character_reference ( $ context , $ text , $ next_character_reference_at , $ token_length );
153149 if ( isset ( $ character_reference ) ) {
154- $ at = $ next_character_reference_at ;
150+ $ at = $ next_character_reference_at ;
155151 $ decoded .= substr ( $ text , $ was_at , $ at - $ was_at );
156152 $ decoded .= $ character_reference ;
157153 $ at += $ token_length ;
158- $ was_at = $ at ;
154+ $ was_at = $ at ;
159155 continue ;
160156 }
161157
162- ++ $ at ;
158+ ++$ at ;
163159 }
164160
165- if ( 0 === $ was_at ) {
161+ if ( $ was_at === 0 ) {
166162 return $ text ;
167163 }
168164
@@ -198,17 +194,16 @@ public static function decode( $context, $text ): string {
198194 * '∉' === WP_HTML_Decoder::read_character_reference( 'data', '∉', 0, $token_length );
199195 * 7 === $token_length; // `∉`
200196 *
201- * @param string $context `attribute` for decoding attribute values, `data` otherwise.
202- * @param string $text Text document containing span of text to decode.
203- * @param int $at Optional. Byte offset into text where span begins, defaults to the beginning (0).
197+ * @param string $context `attribute` for decoding attribute values, `data` otherwise.
198+ * @param string $text Text document containing span of text to decode.
199+ * @param int $at Optional. Byte offset into text where span begins, defaults to the beginning (0).
204200 * @param int &$match_byte_length Optional. Set to byte-length of character reference if provided and if a match
205201 * is found, otherwise not set. Default null.
206202 *
207203 * @return string|false Decoded character reference in UTF-8 if found, otherwise `false`.
208204 * @global WP_Token_Map $html5_named_character_references Mappings for HTML5 named character references.
209205 *
210206 * @since 6.6.0
211- *
212207 */
213208 public static function read_character_reference ( $ context , $ text , $ at = 0 , &$ match_byte_length = null ) {
214209 /**
@@ -223,7 +218,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
223218 return null ;
224219 }
225220
226- if ( ' & ' !== $ text [ $ at ] ) {
221+ if ( $ text [ $ at ] !== ' & ' ) {
227222 return null ;
228223 }
229224
@@ -237,19 +232,19 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
237232 * - fail to parse and return plaintext `DZ`.
238233 * - fail to parse and return the replacement character `�`
239234 */
240- if ( ' # ' === $ text [ $ at + 1 ] ) {
235+ if ( $ text [ $ at + 1 ] === ' # ' ) {
241236 if ( $ at + 2 >= $ length ) {
242237 return null ;
243238 }
244239
245240 /** Tracks inner parsing within the numeric character reference. */
246241 $ digits_at = $ at + 2 ;
247242
248- if ( ' x ' === $ text [ $ digits_at ] || ' X ' === $ text [ $ digits_at ] ) {
243+ if ( $ text [ $ digits_at ] === ' x ' || $ text [ $ digits_at ] === ' X ' ) {
249244 $ numeric_base = 16 ;
250245 $ numeric_digits = '0123456789abcdefABCDEF ' ;
251246 $ max_digits = 6 ; // 
252- ++ $ digits_at ;
247+ ++$ digits_at ;
253248 } else {
254249 $ numeric_base = 10 ;
255250 $ numeric_digits = '0123456789 ' ;
@@ -260,16 +255,16 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
260255 $ zero_count = strspn ( $ text , '0 ' , $ digits_at );
261256 $ digit_count = strspn ( $ text , $ numeric_digits , $ digits_at + $ zero_count );
262257 $ after_digits = $ digits_at + $ zero_count + $ digit_count ;
263- $ has_semicolon = $ after_digits < $ length && ' ; ' === $ text [ $ after_digits ];
258+ $ has_semicolon = $ after_digits < $ length && $ text [ $ after_digits ] === ' ; ' ;
264259 $ end_of_span = $ has_semicolon ? $ after_digits + 1 : $ after_digits ;
265260
266261 // `&#` or `&#x` without digits returns into plaintext.
267- if ( 0 === $ digit_count && 0 === $ zero_count ) {
262+ if ( $ digit_count === 0 && $ zero_count === 0 ) {
268263 return null ;
269264 }
270265
271266 // Whereas `&#` and only zeros is invalid.
272- if ( 0 === $ digit_count ) {
267+ if ( $ digit_count === 0 ) {
273268 $ match_byte_length = $ end_of_span - $ at ;
274269
275270 return '� ' ;
@@ -282,7 +277,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
282277 return '� ' ;
283278 }
284279
285- $ digits = substr ( $ text , $ digits_at + $ zero_count , $ digit_count );
280+ $ digits = substr ( $ text , $ digits_at + $ zero_count , $ digit_count );
286281 $ codepoint = intval ( $ digits , $ numeric_base );
287282
288283 /*
@@ -369,14 +364,14 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
369364
370365 $ name_length = 0 ;
371366 $ replacement = $ html5_named_character_references ->read_token ( $ text , $ name_at , $ name_length );
372- if ( false === $ replacement ) {
367+ if ( $ replacement === false ) {
373368 return null ;
374369 }
375370
376371 $ after_name = $ name_at + $ name_length ;
377372
378373 // If the match ended with a semicolon then it should always be decoded.
379- if ( ' ; ' === $ text [ $ name_at + $ name_length - 1 ] ) {
374+ if ( $ text [ $ name_at + $ name_length - 1 ] === ' ; ' ) {
380375 $ match_byte_length = $ after_name - $ at ;
381376
382377 return $ replacement ;
@@ -392,7 +387,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
392387 $ name_at < $ length &&
393388 (
394389 ctype_alnum ( $ text [ $ after_name ] ) ||
395- ' = ' === $ text [ $ after_name ]
390+ $ text [ $ after_name ] === ' = '
396391 )
397392 );
398393
@@ -404,7 +399,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
404399 }
405400
406401 // It's ambiguous, which isn't allowed inside attributes.
407- if ( ' attribute ' === $ context ) {
402+ if ( $ context === ' attribute ' ) {
408403 return null ;
409404 }
410405
@@ -427,13 +422,12 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat
427422 * // Half of a surrogate pair is an invalid code point.
428423 * '�' === WP_HTML_Decoder::codepoint_to_utf8_bytes( 0xd83c );
429424 *
430- * @param int $codepoint Which code point to convert.
425+ * @param int $codepoint Which code point to convert.
431426 *
432427 * @return string Converted code point, or `�` if invalid.
433428 * @since 6.6.0
434429 *
435430 * @see https://www.rfc-editor.org/rfc/rfc3629 For the UTF-8 standard.
436- *
437431 */
438432 public static function codepoint_to_utf8_bytes ( $ codepoint ): string {
439433 // Pre-check to ensure a valid code point.
0 commit comments