Skip to content

Commit

Permalink
HTML API: Truncated funky comments should cause the Tag Processor to …
Browse files Browse the repository at this point in the history
…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 WordPress#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
  • Loading branch information
dmsnell committed Aug 6, 2024
1 parent 96c2a46 commit 534b830
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,8 @@ private function parse_next_tag(): bool {
if ( $this->is_closing_tag ) {
// No chance of finding a closer.
if ( $at + 3 > $doc_length ) {
$this->parser_state = self::STATE_INCOMPLETE_INPUT;

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlTagProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2903,4 +2903,15 @@ public function test_script_tag_processing_no_infinite_loop_final_left_angle_bra
$this->assertFalse( $processor->next_tag() );
$this->assertTrue( $processor->paused_at_incomplete_token() );
}

/**
* Test a bugfix where the input ends abruptly with a funky comment started.
*
* @ticket 61831
*/
public function test_unclosed_funky_comment_input_too_short() {
$processor = new WP_HTML_Tag_Processor( '</#' );
$this->assertFalse( $processor->next_tag() );
$this->assertTrue( $processor->paused_at_incomplete_token() );
}
}

0 comments on commit 534b830

Please sign in to comment.