Skip to content

Commit 543a0b8

Browse files
committed
Fix span-of-dashes comment modifiable text
1 parent b0aae8a commit 543a0b8

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,13 @@ private function parse_next_tag() {
16031603
*/
16041604
$this->parser_state = self::STATE_COMMENT;
16051605
$this->token_length = $closer_at + $span_of_dashes + 1 - $this->token_starts_at;
1606-
$this->text_starts_at = $this->token_starts_at + 4;
1607-
$this->text_length = max( 0, $closer_at - $this->text_starts_at );
1606+
1607+
// Only provide modifiable text if the token is long enough to contain it.
1608+
if ( $span_of_dashes >= 2 ) {
1609+
$this->text_starts_at = $this->token_starts_at + 4;
1610+
$this->text_length = $span_of_dashes - 2;
1611+
}
1612+
16081613
$this->bytes_already_parsed = $closer_at + $span_of_dashes + 1;
16091614
return true;
16101615
}

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

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,13 @@ public function test_basic_assertion_common_comments( $html, $text ) {
531531
*/
532532
public function data_common_comments() {
533533
return array(
534-
'Shortest comment' => array( '<!-->', '' ),
535-
'Short comment' => array( '<!--->', '' ),
536-
'PI node without target' => array( '<? missing?>', ' missing?' ),
537-
'Invalid PI node' => array( '<?/missing/>', '/missing/' ),
538-
'Invalid ! directive' => array( '<!something else>', 'something else' ),
534+
'Shortest comment' => array( '<!-->', '' ),
535+
'Short comment' => array( '<!--->', '' ),
536+
'Short comment w/o text' => array( '<!---->', '' ),
537+
'Short comment with text' => array( '<!----->', '-' ),
538+
'PI node without target' => array( '<? missing?>', ' missing?' ),
539+
'Invalid PI node' => array( '<?/missing/>', '/missing/' ),
540+
'Invalid ! directive' => array( '<!something else>', 'something else' ),
539541
);
540542
}
541543

@@ -581,26 +583,6 @@ public function test_basic_assertion_html_comment() {
581583
);
582584
}
583585

584-
/**
585-
* Ensures that <!-----> HTML comment is properly parsed.
586-
*
587-
* @ticket 60170
588-
*
589-
* @since 6.5.0
590-
*
591-
* @covers WP_HTML_Tag_Processor::next_token
592-
*/
593-
public function test_html_comment_single_dash() {
594-
$processor = WP_HTML_Processor::create_fragment( '<!----->' );
595-
$processor->next_token();
596-
597-
$this->assertSame(
598-
'-',
599-
$processor->get_modifiable_text(),
600-
'Found incorrect modifiable text.'
601-
);
602-
}
603-
604586
/**
605587
* Ensures that normative DOCTYPE elements are properly parsed.
606588
*

0 commit comments

Comments
 (0)