Skip to content

Commit 8a5805f

Browse files
committed
Process incomplete HTML tokens as raw text anyway
1 parent 1c569dd commit 8a5805f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wp-includes/formatting.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,10 @@ public function extract_raw_token() {
662662

663663
$tokens = array();
664664
$was_text = false;
665+
$next_at = 0;
665666
while ( $token_reporter->next_token() ) {
666667
$raw_token = $token_reporter->extract_raw_token();
668+
$next_at += strlen( $raw_token );
667669
$is_text = '#text' === $token_reporter->get_token_name();
668670

669671
if ( ! $is_text && ! $was_text ) {
@@ -685,6 +687,22 @@ public function extract_raw_token() {
685687
$was_text = $is_text;
686688
}
687689

690+
/*
691+
* The HTML API aborts when a string ends with the start of a
692+
* token which isn’t complete, such as an un-closed comment.
693+
* Typically it’s best to avoid processing or passing along
694+
* that content because it could impact any HTML which follows
695+
* it. However, to maintain backwards compatability this last
696+
* segment needs to appear.
697+
*/
698+
if ( $token_reporter->paused_at_incomplete_token() ) {
699+
if ( ! $was_text ) {
700+
$tokens[] = '';
701+
}
702+
$was_text = false;
703+
$tokens[] = substr( $input, $next_at );
704+
}
705+
688706
if ( ! $was_text ) {
689707
$tokens[] = '';
690708
}

tests/phpunit/tests/shortcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ public function test_spaces_around_shortcodes() {
544544
* @dataProvider data_escaping
545545
*/
546546
public function test_escaping( $input, $output ) {
547-
return $this->assertSame( $output, do_shortcode( $input ) );
547+
return $this->assertEqualHTML( $output, do_shortcode( $input ) );
548548
}
549549

550550
public function data_escaping() {

0 commit comments

Comments
 (0)