Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/html-api/class-wp-html-decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public static function read_character_reference( $context, $text, $at = 0, &$mat

$name_length = 0;
$replacement = $html5_named_character_references->read_token( $text, $name_at, $name_length );
if ( false === $replacement ) {
if ( null === $replacement ) {
return null;
}

Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,39 @@ static function ( int $errno, string $errstr ) use ( &$errors ) {
$this->assertSame( "&\x00b", $decoded, 'Should have decoded the text without changing it.' );
}

/**
* Ensures unmatched named character references leave the by-ref match length unchanged.
*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ticket 65372

* @dataProvider data_unmatched_named_character_references
*
* @ticket 65372
*
* @param string $context Decoder context.
* @param string $raw_text_node Raw text containing an unmatched named character reference.
*/
public function test_unmatched_named_character_reference_does_not_set_match_byte_length( $context, $raw_text_node ): void {
$match_byte_length = 'sentinel';
$this->assertNull(
WP_HTML_Decoder::read_character_reference( $context, $raw_text_node, 0, $match_byte_length ),
'Should not have matched an unmatched named character reference.'
);
$this->assertSame( 'sentinel', $match_byte_length );
}

/**
* Data provider.
*
* @return array<string, array{string, string}>.
*/
public static function data_unmatched_named_character_references(): array {
return array(
'text invalid name' => array( 'data', '&bogus;' ),
'text invalid short-name candidate' => array( 'data', '&Fv=q' ),
'attribute invalid name' => array( 'attribute', '&bogus;' ),
'attribute invalid short-name candidate' => array( 'attribute', '&Fv=q' ),
);
}

/**
* Ensures semicolonless legacy references decode before non-ASCII UTF-8 bytes in attributes.
*
Expand Down
Loading