Skip to content

Commit feb8a0f

Browse files
committed
RAWTEXT and SCRIPT elements do no decode character references
1 parent cd5efbd commit feb8a0f

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,7 @@ public function get_modifiable_text() {
27032703

27042704
$text = substr( $this->html, $this->text_starts_at, $this->text_length );
27052705

2706+
// Comment data is not decoded.
27062707
if (
27072708
self::STATE_CDATA_NODE === $this->parser_state ||
27082709
self::STATE_COMMENT === $this->parser_state ||
@@ -2713,6 +2714,21 @@ public function get_modifiable_text() {
27132714
return $text;
27142715
}
27152716

2717+
$tag_name = $this->get_tag();
2718+
if (
2719+
// Script data is not decoded.
2720+
'SCRIPT' === $tag_name ||
2721+
2722+
// RAWTEXT data is not decoded.
2723+
'IFRAME' === $tag_name ||
2724+
'NOEMBED' === $tag_name ||
2725+
'NOFRAMES' === $tag_name ||
2726+
'STYLE' === $tag_name ||
2727+
'XMP' === $tag_name
2728+
) {
2729+
return $text;
2730+
}
2731+
27162732
$decoded = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE );
27172733

27182734
if ( empty( $decoded ) ) {
@@ -2726,7 +2742,7 @@ public function get_modifiable_text() {
27262742
* for a leading newline and removing it.
27272743
*/
27282744
if ( self::STATE_MATCHED_TAG === $this->parser_state ) {
2729-
switch ( $this->get_tag() ) {
2745+
switch ( $tag_name ) {
27302746
case 'PRE':
27312747
case 'TEXTAREA':
27322748
if ( "\n" === $decoded[0] ) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function test_basic_assertion_rawtext_elements( $tag_name ) {
284284
);
285285

286286
$this->assertSame(
287-
"\nIs <HTML> > XHTML?\n",
287+
"\nIs <HTML> &gt; XHTML?\n",
288288
$processor->get_modifiable_text(),
289289
'Found incorrect modifiable text.'
290290
);
@@ -378,6 +378,12 @@ public function test_basic_assertion_abruptly_closed_cdata_section() {
378378

379379
$processor->next_token();
380380

381+
$this->assertSame(
382+
'#text',
383+
$processor->get_token_name(),
384+
"Should have found text node but found {$processor->get_token_name()} instead."
385+
);
386+
381387
$this->assertSame(
382388
' a comment]]>',
383389
$processor->get_modifiable_text(),

0 commit comments

Comments
 (0)