Skip to content

Commit 534b830

Browse files
committed
HTML API: Truncated funky comments should cause the Tag Processor to pause.
A state change was missing in the Tag Processor when the input is too short to find a comment closer after an opened funky comment. This patch fixes a issue where `</#` does not correctly report incomplete input, but `</# ` does. Developed in #7146 Discussed in https://core.trac.wordpress.org/ticket/61831 Props: jonsurrell. Fixes #61831. git-svn-id: https://develop.svn.wordpress.org/trunk@58858 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 96c2a46 commit 534b830

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,8 @@ private function parse_next_tag(): bool {
19091909
if ( $this->is_closing_tag ) {
19101910
// No chance of finding a closer.
19111911
if ( $at + 3 > $doc_length ) {
1912+
$this->parser_state = self::STATE_INCOMPLETE_INPUT;
1913+
19121914
return false;
19131915
}
19141916

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,4 +2903,15 @@ public function test_script_tag_processing_no_infinite_loop_final_left_angle_bra
29032903
$this->assertFalse( $processor->next_tag() );
29042904
$this->assertTrue( $processor->paused_at_incomplete_token() );
29052905
}
2906+
2907+
/**
2908+
* Test a bugfix where the input ends abruptly with a funky comment started.
2909+
*
2910+
* @ticket 61831
2911+
*/
2912+
public function test_unclosed_funky_comment_input_too_short() {
2913+
$processor = new WP_HTML_Tag_Processor( '</#' );
2914+
$this->assertFalse( $processor->next_tag() );
2915+
$this->assertTrue( $processor->paused_at_incomplete_token() );
2916+
}
29062917
}

0 commit comments

Comments
 (0)