Skip to content

Commit 23a058a

Browse files
committed
Add references to Trac ticket, annotate tests
1 parent 2f22fda commit 23a058a

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ private function skip_script_data() {
971971
* closing `>`; these are left for other methods.
972972
*
973973
* @since 6.2.0
974+
* @since 6.3.0 Passes over invalid-tag-closer-comments like "</3 this is a comment>".
974975
*
975976
* @return bool Whether a tag was found before the end of the document.
976977
*/

tests/phpunit/tests/html-api/wpHtmlTagProcessor.php

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,39 +1669,38 @@ public function data_next_tag_ignores_script_tag_contents() {
16691669
*
16701670
* See https://html.spec.whatwg.org/#parse-error-invalid-first-character-of-tag-name
16711671
*
1672+
* @ticket 58007
16721673
* @dataProvider data_next_tag_ignores_invalid_first_character_of_tag_name_comments
16731674
*
1674-
* @param $html_with_markers
1675-
* @param $before_tag
1676-
* @param $after_tag
1677-
* @return void
1675+
* @param string $html_with_markers HTML containing an invalid tag closer whose element before and element after contain the "start" and "end" CSS classes.
16781676
*/
1679-
public function test_next_tag_ignores_invalid_first_character_of_tag_name_comments( $html_with_markers, $before_tag, $after_tag ) {
1677+
public function test_next_tag_ignores_invalid_first_character_of_tag_name_comments( $html_with_markers ) {
16801678
$p = new WP_HTML_Tag_Processor( $html_with_markers );
1681-
$p->next_tag( $before_tag );
1679+
$p->next_tag( array( 'class_name' => 'start' ) );
16821680
$p->next_tag();
16831681

1684-
$this->assertSame( $after_tag, $p->get_tag() );
1682+
$this->assertSame( 'end', $p->get_attribute( 'class' ) );
16851683
}
16861684

1685+
/**
1686+
* Data provider.
1687+
*
1688+
* @ticket 58007
1689+
*
1690+
* @return array[]
1691+
*/
16871692
public function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() {
16881693
return array(
16891694
'Invalid tag openers as normal text' => array(
1690-
'<ul><li><div>I <3 when outflow > inflow</div><img></li></ul>',
1691-
'DIV',
1692-
'IMG',
1695+
'<ul><li><div class=start>I <3 when outflow > inflow</div><img class=end></li></ul>',
16931696
),
16941697

16951698
'Invalid tag closers as comments' => array(
1696-
'<ul><li><div>I </3 when <img> outflow <br> inflow</div></li></ul>',
1697-
'DIV',
1698-
'BR',
1699+
'<ul><li><div class=start>I </3 when <img> outflow <br class=end> inflow</div></li></ul>',
16991700
),
17001701

17011702
'Unexpected question mark instead of tag name' => array(
1702-
'<div><?xml-stylesheet type="text/css" href="style.css"?><hr>',
1703-
'DIV',
1704-
'HR',
1703+
'<div class=start><?xml-stylesheet type="text/css" href="style.css"?><hr class=end>',
17051704
),
17061705
);
17071706
}
@@ -1758,6 +1757,13 @@ public function data_next_tag_ignores_contents_of_rcdata_tag() {
17581757
);
17591758
}
17601759

1760+
/**
1761+
* Ensures that the invalid comment closing syntax "--!>" properly closes a comment.
1762+
*
1763+
* @ticket 58007
1764+
* @covers WP_HTML_Tag_Processor::next_tag
1765+
*
1766+
*/
17611767
public function test_allows_incorrectly_closed_comments() {
17621768
$p = new WP_HTML_Tag_Processor( '<img id=before><!-- <img id=inside> --!><img id=after>--><img id=final>' );
17631769

@@ -1772,19 +1778,29 @@ public function test_allows_incorrectly_closed_comments() {
17721778
}
17731779

17741780
/**
1781+
* Ensures that abruptly-closed empty comments are properly closed.
1782+
*
1783+
* @ticket 58007
1784+
* @covers WP_HTML_Tag_Processor::next_tag
17751785
* @dataProvider data_abruptly_closed_empty_comments
17761786
*
1777-
* @param $html
1778-
* @return void
1787+
* @param string $html_with_after_marker HTML to test with "id=after" on element immediately following an abruptly closed comment.
17791788
*/
1780-
public function test_closes_abrupt_closing_of_empty_comment( $html ) {
1781-
$p = new WP_HTML_Tag_Processor( $html );
1789+
public function test_closes_abrupt_closing_of_empty_comment( $html_with_after_marker ) {
1790+
$p = new WP_HTML_Tag_Processor( $html_with_after_marker );
17821791
$p->next_tag();
17831792
$p->next_tag();
17841793

17851794
$this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not find tag after closing abruptly-closed comment' );
17861795
}
17871796

1797+
/**
1798+
* Data provider.
1799+
*
1800+
* @ticket 58007
1801+
*
1802+
* @return array[]
1803+
*/
17881804
public function data_abruptly_closed_empty_comments() {
17891805
return array(
17901806
'Empty comment with two dashes only' => array( '<hr><!--><hr id=after>' ),

0 commit comments

Comments
 (0)