@@ -2106,27 +2106,26 @@ private function parse_next_tag() {
21062106 * `<?` denotes a processing instruction.
21072107 * See https://www.w3.org/TR/xml/#sec-pi
21082108 */
2109- if (
2110- ! $ this ->is_closing_tag &&
2111- '? ' === $ xml [ $ at + 1 ]
2112- ) {
2113- if ( $ at + 4 >= $ doc_length ) {
2109+ if ( ! $ this ->is_closing_tag && '? ' === $ xml [ $ at + 1 ] ) {
2110+ if ( $ at + 2 >= $ doc_length ) {
21142111 $ this ->mark_incomplete_input ();
21152112
21162113 return false ;
21172114 }
21182115
2119- if ( ! (
2120- ( 'x ' === $ xml [ $ at + 2 ] || 'X ' === $ xml [ $ at + 2 ] ) &&
2121- ( 'm ' === $ xml [ $ at + 3 ] || 'M ' === $ xml [ $ at + 3 ] ) &&
2122- ( 'l ' === $ xml [ $ at + 4 ] || 'L ' === $ xml [ $ at + 4 ] )
2123- ) ) {
2116+ $ target_length = $ this ->parse_name ( $ at + 2 );
2117+ if ( false === $ target_length ) {
2118+ return false ;
2119+ }
2120+
2121+ if ( 0 === $ target_length ) {
21242122 $ this ->bail ( 'Invalid processing instruction target. ' , self ::ERROR_SYNTAX );
21252123 }
21262124
2127- $ at += 5 ;
2125+ $ target_ends_at = $ at + 2 + $ target_length ;
2126+ $ this ->bytes_already_parsed = $ target_ends_at ;
21282127
2129- // Skip whitespace.
2128+ // Skip whitespace after the target, if any .
21302129 $ this ->skip_whitespace ();
21312130
21322131 /*
@@ -2141,16 +2140,16 @@ private function parse_next_tag() {
21412140 * closing ?> is found. Some failures may pass unnoticed. That may not be a problem in practice,
21422141 * but if it is then this code path will require a stricter implementation.
21432142 */
2144- $ closer_at = strpos ( $ xml , '?> ' , $ at );
2143+ $ closer_at = strpos ( $ xml , '?> ' , $ this -> bytes_already_parsed );
21452144 if ( false === $ closer_at ) {
21462145 $ this ->mark_incomplete_input ();
21472146
21482147 return false ;
21492148 }
21502149
21512150 $ this ->parser_state = self ::STATE_PI_NODE ;
2152- $ this ->token_length = $ closer_at + 5 - $ this ->token_starts_at ;
2153- $ this ->text_starts_at = $ this -> token_starts_at + 5 ;
2151+ $ this ->token_length = $ closer_at + 2 - $ this ->token_starts_at ;
2152+ $ this ->text_starts_at = $ target_ends_at ;
21542153 $ this ->text_length = $ closer_at - $ this ->text_starts_at ;
21552154 $ this ->bytes_already_parsed = $ closer_at + 2 ;
21562155
0 commit comments