@@ -1827,10 +1827,42 @@ public function test_allows_incorrectly_closed_comments() {
18271827 $ this ->assertSame ( 'final ' , $ p ->get_attribute ( 'id ' ), 'Did not skip over unopened comment-closer. ' );
18281828 }
18291829
1830+ /**
1831+ * Ensures that unclosed and invalid comments don't trigger warnings or errors.
1832+ *
1833+ * @ticket 58007
1834+ *
1835+ * @covers WP_HTML_Tag_Processor::next_tag
1836+ * @dataProvider data_html_with_unclosed_comments
1837+ *
1838+ * @param string $html_ending_before_comment_close HTML with opened comments that aren't closed
1839+ */
1840+ public function test_documents_may_end_with_unclosed_comment ( $ html_ending_before_comment_close ) {
1841+ $ p = new WP_HTML_Tag_Processor ( $ html_ending_before_comment_close );
1842+
1843+ $ this ->assertFalse ( $ p ->next_tag () );
1844+ }
1845+
1846+ /**
1847+ * Data provider.
1848+ *
1849+ * @return array[]
1850+ */
1851+ public function data_html_with_unclosed_comments () {
1852+ return array (
1853+ 'Basic truncated comment ' => array ( '<!-- this ends -- ' ),
1854+ 'Comment with closer look-alike ' => array ( '<!-- this ends --x ' ),
1855+ 'Comment with closer look-alike 2 ' => array ( '<!-- this ends --!x ' ),
1856+ 'Invalid tag-closer comment ' => array ( '</(when will this madness end?) ' ),
1857+ 'Invalid tag-closer comment 2 ' => array ( '</(when will this madness end?)-- ' )
1858+ );
1859+ }
1860+
18301861 /**
18311862 * Ensures that abruptly-closed empty comments are properly closed.
18321863 *
18331864 * @ticket 58007
1865+ *
18341866 * @covers WP_HTML_Tag_Processor::next_tag
18351867 * @dataProvider data_abruptly_closed_empty_comments
18361868 *
@@ -1847,8 +1879,6 @@ public function test_closes_abrupt_closing_of_empty_comment( $html_with_after_ma
18471879 /**
18481880 * Data provider.
18491881 *
1850- * @ticket 58007
1851- *
18521882 * @return array[]
18531883 */
18541884 public function data_abruptly_closed_empty_comments () {
0 commit comments