- Timestamp:
- 03/12/2024 12:22:40 AM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-processor.php
r57768 r57806 362 362 if ( null === $query ) { 363 363 while ( $this->step() ) { 364 if ( '#tag' !== $this->get_token_type() ) { 365 continue; 366 } 367 364 368 if ( ! $this->is_tag_closer() ) { 365 369 return true; … … 385 389 if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) { 386 390 while ( $this->step() ) { 391 if ( '#tag' !== $this->get_token_type() ) { 392 continue; 393 } 394 387 395 if ( ! $this->is_tag_closer() ) { 388 396 return true; … … 406 414 407 415 while ( $match_offset > 0 && $this->step() ) { 416 if ( '#tag' !== $this->get_token_type() ) { 417 continue; 418 } 419 408 420 if ( $this->matches_breadcrumbs( $breadcrumbs ) && 0 === --$match_offset ) { 409 421 return true; … … 429 441 */ 430 442 public function next_token() { 431 $found_a_token = parent::next_token(); 432 433 if ( '#tag' === $this->get_token_type() ) { 434 $this->step( self::PROCESS_CURRENT_NODE ); 435 } 436 437 return $found_a_token; 443 return $this->step(); 438 444 } 439 445 … … 464 470 */ 465 471 public function matches_breadcrumbs( $breadcrumbs ) { 466 if ( ! $this->get_tag() ) {467 return false;468 }469 470 472 // Everything matches when there are zero constraints. 471 473 if ( 0 === count( $breadcrumbs ) ) { … … 530 532 */ 531 533 $top_node = $this->state->stack_of_open_elements->current_node(); 532 if ( $top_node && self::is_void( $top_node->node_name ) ) { 534 if ( 535 $top_node && ( 536 // Void elements. 537 self::is_void( $top_node->node_name ) || 538 // Comments, text nodes, and other atomic tokens. 539 '#' === $top_node->node_name[0] || 540 // Doctype declarations. 541 'html' === $top_node->node_name 542 ) 543 ) { 533 544 $this->state->stack_of_open_elements->pop(); 534 545 } … … 536 547 537 548 if ( self::PROCESS_NEXT_NODE === $node_to_process ) { 538 while ( parent::next_token() && '#tag' !== $this->get_token_type() ) { 539 continue; 540 } 549 parent::next_token(); 541 550 } 542 551 543 552 // Finish stepping when there are no more tokens in the document. 544 if ( null === $this->get_tag() ) { 553 if ( 554 WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT === $this->parser_state || 555 WP_HTML_Tag_Processor::STATE_COMPLETE === $this->parser_state 556 ) { 545 557 return false; 546 558 } 547 559 548 560 $this->state->current_token = new WP_HTML_Token( 549 $this->bookmark_t ag(),550 $this->get_t ag(),561 $this->bookmark_token(), 562 $this->get_token_name(), 551 563 $this->has_self_closing_flag(), 552 564 $this->release_internal_bookmark_on_destruct … … 592 604 */ 593 605 public function get_breadcrumbs() { 594 if ( ! $this->get_tag() ) {595 return null;596 }597 598 606 $breadcrumbs = array(); 599 607 foreach ( $this->state->stack_of_open_elements->walk_down() as $stack_item ) { … … 620 628 */ 621 629 private function step_in_body() { 622 $tag_name = $this->get_tag(); 623 $op_sigil = $this->is_tag_closer() ? '-' : '+'; 624 $op = "{$op_sigil}{$tag_name}"; 630 $token_name = $this->get_token_name(); 631 $token_type = $this->get_token_type(); 632 $op_sigil = '#tag' === $token_type ? ( $this->is_tag_closer() ? '-' : '+' ) : ''; 633 $op = "{$op_sigil}{$token_name}"; 625 634 626 635 switch ( $op ) { 636 case '#comment': 637 case '#funky-comment': 638 case '#presumptuous-tag': 639 $this->insert_html_element( $this->state->current_token ); 640 return true; 641 642 case '#text': 643 $this->reconstruct_active_formatting_elements(); 644 645 $current_token = $this->bookmarks[ $this->state->current_token->bookmark_name ]; 646 647 /* 648 * > A character token that is U+0000 NULL 649 * 650 * Any successive sequence of NULL bytes is ignored and won't 651 * trigger active format reconstruction. Therefore, if the text 652 * only comprises NULL bytes then the token should be ignored 653 * here, but if there are any other characters in the stream 654 * the active formats should be reconstructed. 655 */ 656 if ( 657 1 <= $current_token->length && 658 "\x00" === $this->html[ $current_token->start ] && 659 strspn( $this->html, "\x00", $current_token->start, $current_token->length ) === $current_token->length 660 ) { 661 // Parse error: ignore the token. 662 return $this->step(); 663 } 664 665 /* 666 * Whitespace-only text does not affect the frameset-ok flag. 667 * It is probably inter-element whitespace, but it may also 668 * contain character references which decode only to whitespace. 669 */ 670 $text = $this->get_modifiable_text(); 671 if ( strlen( $text ) !== strspn( $text, " \t\n\f\r" ) ) { 672 $this->state->frameset_ok = false; 673 } 674 675 $this->insert_html_element( $this->state->current_token ); 676 return true; 677 678 case 'html': 679 /* 680 * > A DOCTYPE token 681 * > Parse error. Ignore the token. 682 */ 683 return $this->step(); 684 627 685 /* 628 686 * > A start tag whose tag name is "button" … … 712 770 case '-SUMMARY': 713 771 case '-UL': 714 if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $t ag_name ) ) {772 if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $token_name ) ) { 715 773 // @todo Report parse error. 716 774 // Ignore the token. … … 719 777 720 778 $this->generate_implied_end_tags(); 721 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $t ag_name ) {779 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name ) { 722 780 // @todo Record parse error: this error doesn't impact parsing. 723 781 } 724 $this->state->stack_of_open_elements->pop_until( $t ag_name );782 $this->state->stack_of_open_elements->pop_until( $token_name ); 725 783 return true; 726 784 … … 784 842 $this->generate_implied_end_tags(); 785 843 786 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $t ag_name ) {844 if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name ) { 787 845 // @todo Record parse error: this error doesn't impact parsing. 788 846 } … … 800 858 $this->state->frameset_ok = false; 801 859 $node = $this->state->stack_of_open_elements->current_node(); 802 $is_li = 'LI' === $t ag_name;860 $is_li = 'LI' === $token_name; 803 861 804 862 in_body_list_loop: … … 863 921 */ 864 922 ( 865 'LI' === $t ag_name &&923 'LI' === $token_name && 866 924 ! $this->state->stack_of_open_elements->has_element_in_list_item_scope( 'LI' ) 867 925 ) || … … 873 931 */ 874 932 ( 875 'LI' !== $t ag_name &&876 ! $this->state->stack_of_open_elements->has_element_in_scope( $t ag_name )933 'LI' !== $token_name && 934 ! $this->state->stack_of_open_elements->has_element_in_scope( $token_name ) 877 935 ) 878 936 ) { … … 885 943 } 886 944 887 $this->generate_implied_end_tags( $t ag_name );888 889 if ( $t ag_name !== $this->state->stack_of_open_elements->current_node()->node_name ) {945 $this->generate_implied_end_tags( $token_name ); 946 947 if ( $token_name !== $this->state->stack_of_open_elements->current_node()->node_name ) { 890 948 // @todo Indicate a parse error once it's possible. This error does not impact the logic here. 891 949 } 892 950 893 $this->state->stack_of_open_elements->pop_until( $t ag_name );951 $this->state->stack_of_open_elements->pop_until( $token_name ); 894 952 return true; 895 953 … … 1044 1102 * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody 1045 1103 */ 1046 switch ( $t ag_name ) {1104 switch ( $token_name ) { 1047 1105 case 'APPLET': 1048 1106 case 'BASE': … … 1092 1150 case 'XMP': 1093 1151 $this->last_error = self::ERROR_UNSUPPORTED; 1094 throw new WP_HTML_Unsupported_Exception( "Cannot process {$t ag_name} element." );1152 throw new WP_HTML_Unsupported_Exception( "Cannot process {$token_name} element." ); 1095 1153 } 1096 1154 … … 1114 1172 */ 1115 1173 foreach ( $this->state->stack_of_open_elements->walk_up() as $node ) { 1116 if ( $t ag_name === $node->node_name ) {1174 if ( $token_name === $node->node_name ) { 1117 1175 break; 1118 1176 } … … 1124 1182 } 1125 1183 1126 $this->generate_implied_end_tags( $t ag_name );1184 $this->generate_implied_end_tags( $token_name ); 1127 1185 if ( $node !== $this->state->stack_of_open_elements->current_node() ) { 1128 1186 // @todo Record parse error: this error doesn't impact parsing. … … 1143 1201 1144 1202 /** 1145 * Creates a new bookmark for the currently-matched tag and returns the generated name. 1146 * 1147 * @since 6.4.0 1203 * Creates a new bookmark for the currently-matched token and returns the generated name. 1204 * 1205 * @since 6.4.0 1206 * @since 6.5.0 Renamed from bookmark_tag() to bookmark_token(). 1148 1207 * 1149 1208 * @throws Exception When unable to allocate requested bookmark. … … 1151 1210 * @return string|false Name of created bookmark, or false if unable to create. 1152 1211 */ 1153 private function bookmark_tag() { 1154 if ( ! $this->get_tag() ) { 1155 return false; 1156 } 1157 1212 private function bookmark_token() { 1158 1213 if ( ! parent::set_bookmark( ++$this->bookmark_counter ) ) { 1159 1214 $this->last_error = self::ERROR_EXCEEDED_MAX_BOOKMARKS;
Note: See TracChangeset
for help on using the changeset viewer.