Changeset 58233
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r58040 r58233 927 927 } 928 928 $this->parser_state = self::STATE_MATCHED_TAG; 929 $this->token_length = $tag_ends_at - $this->token_starts_at;930 929 $this->bytes_already_parsed = $tag_ends_at + 1; 930 $this->token_length = $this->bytes_already_parsed - $this->token_starts_at; 931 931 932 932 /* … … 1014 1014 $this->token_starts_at = $was_at; 1015 1015 $this->token_length = $this->bytes_already_parsed - $this->token_starts_at; 1016 $this->text_starts_at = $tag_ends_at + 1;1016 $this->text_starts_at = $tag_ends_at; 1017 1017 $this->text_length = $this->tag_name_starts_at - $this->text_starts_at; 1018 1018 $this->tag_name_starts_at = $tag_name_starts_at; … … 2688 2688 * ^ this appears one character before the end of the closing ">". 2689 2689 */ 2690 return '/' === $this->html[ $this->token_starts_at + $this->token_length - 1];2690 return '/' === $this->html[ $this->token_starts_at + $this->token_length - 2 ]; 2691 2691 } 2692 2692 -
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php
r57649 r58233 108 108 $bookmark = 'append_content_after_template_tag_closer'; 109 109 $this->set_bookmark( $bookmark ); 110 $after_closing_tag = $this->bookmarks[ $bookmark ]->start + $this->bookmarks[ $bookmark ]->length + 1;110 $after_closing_tag = $this->bookmarks[ $bookmark ]->start + $this->bookmarks[ $bookmark ]->length; 111 111 $this->release_bookmark( $bookmark ); 112 112 … … 141 141 list( $opener_tag, $closer_tag ) = $bookmarks; 142 142 143 $after_opener_tag = $this->bookmarks[ $opener_tag ]->start + $this->bookmarks[ $opener_tag ]->length + 1;143 $after_opener_tag = $this->bookmarks[ $opener_tag ]->start + $this->bookmarks[ $opener_tag ]->length; 144 144 $before_closer_tag = $this->bookmarks[ $closer_tag ]->start; 145 145 -
trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php
r57805 r58233 475 475 476 476 $this->assertSame( '<div wonky><img hidden></div>', $processor->get_updated_html() ); 477 } 478 479 /** 480 * Ensures that bookmarks start and length correctly describe a given token in HTML. 481 * 482 * @ticket 61301 483 * 484 * @dataProvider data_html_nth_token_substring 485 * 486 * @param string $html Input HTML. 487 * @param int $match_nth_token Which token to inspect from input HTML. 488 * @param string $expected_match Expected full raw token bookmark should capture. 489 */ 490 public function test_token_bookmark_span( string $html, int $match_nth_token, string $expected_match ) { 491 $processor = new class( $html ) extends WP_HTML_Tag_Processor { 492 /** 493 * Returns the raw span of HTML for the currently-matched 494 * token, or null if not paused on any token. 495 * 496 * @return string|null Raw HTML content of currently-matched token, 497 * otherwise `null` if not matched. 498 */ 499 public function get_raw_token() { 500 if ( 501 WP_HTML_Tag_Processor::STATE_READY === $this->parser_state || 502 WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT === $this->parser_state || 503 WP_HTML_Tag_Processor::STATE_COMPLETE === $this->parser_state 504 ) { 505 return null; 506 } 507 508 $this->set_bookmark( 'mark' ); 509 $mark = $this->bookmarks['mark']; 510 511 return substr( $this->html, $mark->start, $mark->length ); 512 } 513 }; 514 515 for ( $i = 0; $i < $match_nth_token; $i++ ) { 516 $processor->next_token(); 517 } 518 519 $raw_token = $processor->get_raw_token(); 520 $this->assertIsString( 521 $raw_token, 522 "Failed to find raw token at position {$match_nth_token}: check test data provider." 523 ); 524 525 $this->assertSame( 526 $expected_match, 527 $raw_token, 528 'Bookmarked wrong span of text for full matched token.' 529 ); 530 } 531 532 /** 533 * Data provider. 534 * 535 * @return array 536 */ 537 public static function data_html_nth_token_substring() { 538 return array( 539 // Tags. 540 'DIV start tag' => array( '<div>', 1, '<div>' ), 541 'DIV start tag with attributes' => array( '<div class="x" disabled>', 1, '<div class="x" disabled>' ), 542 'DIV end tag' => array( '</div>', 1, '</div>' ), 543 'DIV end tag with attributes' => array( '</div class="x" disabled>', 1, '</div class="x" disabled>' ), 544 'Nested DIV' => array( '<div><div b>', 2, '<div b>' ), 545 'Sibling DIV' => array( '<div></div><div b>', 3, '<div b>' ), 546 'DIV after text' => array( 'text <div>', 2, '<div>' ), 547 'DIV before text' => array( '<div> text', 1, '<div>' ), 548 'DIV after comment' => array( '<!-- comment --><div>', 2, '<div>' ), 549 'DIV before comment' => array( '<div><!-- c --> ', 1, '<div>' ), 550 'Start "self-closing" tag' => array( '<div />', 1, '<div />' ), 551 'Void tag' => array( '<img src="img.png">', 1, '<img src="img.png">' ), 552 'Void tag w/self-closing flag' => array( '<img src="img.png" />', 1, '<img src="img.png" />' ), 553 'Void tag inside DIV' => array( '<div><img src="img.png"></div>', 2, '<img src="img.png">' ), 554 555 // Special atomic tags. 556 'SCRIPT tag' => array( '<script>inside text</script>', 1, '<script>inside text</script>' ), 557 'SCRIPT double-escape' => array( '<script><!-- <script> echo "</script>"; </script><div>', 1, '<script><!-- <script> echo "</script>"; </script>' ), 558 559 // Text. 560 'Text' => array( 'Just text', 1, 'Just text' ), 561 'Text in DIV' => array( '<div>Text<div>', 2, 'Text' ), 562 'Text before DIV' => array( 'Text<div>', 1, 'Text' ), 563 'Text after DIV' => array( '<div></div>Text', 3, 'Text' ), 564 'Text after comment' => array( '<!-- comment -->Text', 2, 'Text' ), 565 'Text before comment' => array( 'Text<!-- c --> ', 1, 'Text' ), 566 567 // Comments. 568 'Comment' => array( '<!-- comment -->', 1, '<!-- comment -->' ), 569 'Comment in DIV' => array( '<div><!-- comment --><div>', 2, '<!-- comment -->' ), 570 'Comment before DIV' => array( '<!-- comment --><div>', 1, '<!-- comment -->' ), 571 'Comment after DIV' => array( '<div></div><!-- comment -->', 3, '<!-- comment -->' ), 572 'Comment after comment' => array( '<!-- comment --><!-- comment -->', 2, '<!-- comment -->' ), 573 'Comment before comment' => array( '<!-- comment --><!-- c --> ', 1, '<!-- comment -->' ), 574 'Abruptly closed comment' => array( '<!-->', 1, '<!-->' ), 575 'Empty comment' => array( '<!---->', 1, '<!---->' ), 576 'Funky comment' => array( '</_ funk >', 1, '</_ funk >' ), 577 'PI lookalike comment' => array( '<?processing instruction?>', 1, '<?processing instruction?>' ), 578 'CDATA lookalike comment' => array( '<![CDATA[ see? data ]]>', 1, '<![CDATA[ see? data ]]>' ), 579 ); 477 580 } 478 581 … … 2747 2850 $this->set_bookmark( 'here' ); 2748 2851 $this->lexical_updates[] = new WP_HTML_Text_Replacement( 2749 $this->bookmarks['here']->start + $this->bookmarks['here']->length + 1,2852 $this->bookmarks['here']->start + $this->bookmarks['here']->length, 2750 2853 0, 2751 2854 $new_html
Note: See TracChangeset
for help on using the changeset viewer.