Skip to content
Open
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
31 changes: 31 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,37 @@
$this->assertSame( "&\x00b", $decoded, 'Should have decoded the text without changing it.' );
}

/**
* Ensures unmatched named character references leave the by-ref match length unchanged.
*
* @dataProvider data_unmatched_named_character_references
*
* @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 ) {
$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[].
*/
public static function data_unmatched_named_character_references() {
return array(
'text invalid name' => array( 'data', '&bogus;' ),

Check warning on line 88 in tests/phpunit/tests/html-api/wpHtmlDecoder.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 22 space(s) between "'text invalid name'" and double arrow, but found 23.
'text invalid short-name candidate' => array( 'data', '&Fv=q' ),

Check warning on line 89 in tests/phpunit/tests/html-api/wpHtmlDecoder.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 6 space(s) between "'text invalid short-name candidate'" and double arrow, but found 7.
'attribute invalid name' => array( 'attribute', '&bogus;' ),

Check warning on line 90 in tests/phpunit/tests/html-api/wpHtmlDecoder.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 17 space(s) between "'attribute invalid name'" and double arrow, but found 18.
'attribute invalid short-name candidate' => array( 'attribute', '&Fv=q' ),

Check warning on line 91 in tests/phpunit/tests/html-api/wpHtmlDecoder.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Array double arrow not aligned correctly; expected 1 space(s) between "'attribute invalid short-name candidate'" and double arrow, but found 2.
);
}

/**
* Ensures proper detection of attribute prefixes ignoring ASCII case.
*
Expand Down
Loading