- Timestamp:
- 04/20/2023 05:15:40 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.2/src/wp-includes/html-api/class-wp-html-tag-processor.php
r55662 r55668 972 972 * 973 973 * @since 6.2.0 974 * @since 6.2.1 Support abruptly-closed comments, invalid-tag-closer-comments, and empty elements. 974 975 * 975 976 * @return bool Whether a tag was found before the end of the document. … … 1040 1041 '-' === $html[ $at + 3 ] 1041 1042 ) { 1042 $closer_at = strpos( $html, '-->', $at + 4 ); 1043 if ( false === $closer_at ) { 1043 $closer_at = $at + 4; 1044 // If it's not possible to close the comment then there is nothing more to scan. 1045 if ( strlen( $html ) <= $closer_at ) { 1044 1046 return false; 1045 1047 } 1046 1048 1047 $at = $closer_at + 3; 1048 continue; 1049 // Abruptly-closed empty comments are a sequence of dashes followed by `>`. 1050 $span_of_dashes = strspn( $html, '-', $closer_at ); 1051 if ( '>' === $html[ $closer_at + $span_of_dashes ] ) { 1052 $at = $closer_at + $span_of_dashes + 1; 1053 continue; 1054 } 1055 1056 /* 1057 * Comments may be closed by either a --> or an invalid --!>. 1058 * The first occurrence closes the comment. 1059 * 1060 * See https://html.spec.whatwg.org/#parse-error-incorrectly-closed-comment 1061 */ 1062 $closer_at--; // Pre-increment inside condition below reduces risk of accidental infinite looping. 1063 while ( ++$closer_at < strlen( $html ) ) { 1064 $closer_at = strpos( $html, '--', $closer_at ); 1065 if ( false === $closer_at ) { 1066 return false; 1067 } 1068 1069 if ( $closer_at + 2 < strlen( $html ) && '>' === $html[ $closer_at + 2 ] ) { 1070 $at = $closer_at + 3; 1071 continue 2; 1072 } 1073 1074 if ( $closer_at + 3 < strlen( $html ) && '!' === $html[ $closer_at + 2 ] && '>' === $html[ $closer_at + 3 ] ) { 1075 $at = $closer_at + 4; 1076 continue 2; 1077 } 1078 } 1049 1079 } 1050 1080 … … 1106 1136 1107 1137 /* 1138 * </> is a missing end tag name, which is ignored. 1139 * 1140 * See https://html.spec.whatwg.org/#parse-error-missing-end-tag-name 1141 */ 1142 if ( '>' === $html[ $at + 1 ] ) { 1143 $at++; 1144 continue; 1145 } 1146 1147 /* 1108 1148 * <? transitions to a bogus comment state – skip to the nearest > 1109 * https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state1149 * See https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state 1110 1150 */ 1111 1151 if ( '?' === $html[ $at + 1 ] ) { 1112 1152 $closer_at = strpos( $html, '>', $at + 2 ); 1153 if ( false === $closer_at ) { 1154 return false; 1155 } 1156 1157 $at = $closer_at + 1; 1158 continue; 1159 } 1160 1161 /* 1162 * If a non-alpha starts the tag name in a tag closer it's a comment. 1163 * Find the first `>`, which closes the comment. 1164 * 1165 * See https://html.spec.whatwg.org/#parse-error-invalid-first-character-of-tag-name 1166 */ 1167 if ( $this->is_closing_tag ) { 1168 $closer_at = strpos( $html, '>', $at + 3 ); 1113 1169 if ( false === $closer_at ) { 1114 1170 return false;
Note: See TracChangeset
for help on using the changeset viewer.