Skip to content

Commit a96d8ac

Browse files
committed
Handle \r as tag name terminator
1 parent 981d8e1 commit a96d8ac

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/wp-includes/functions.wp-scripts.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ function wp_add_inline_script( $handle, $data, $position = 'after' ) {
139139
(
140140
"\t" === $data[7] ||
141141
"\n" === $data[7] ||
142+
/*
143+
* \r\n and \r are normalized to \n in HTML newline normalization.
144+
* Therefore, \r always behaves like \n and terminates a tag name.
145+
*/
146+
"\r" === $data[7] ||
142147
"\f" === $data[7] ||
143148
' ' === $data[7] ||
144149
'/' === $data[7] ||

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,14 +3745,15 @@ public function set_modifiable_text( string $plaintext_content ): bool {
37453745
* 4. One of the following characters:
37463746
* - \t
37473747
* - \n
3748+
* - \r (\r and \r\n newlines are normalized to \n in HTML pre-processing)
37483749
* - \f
37493750
* - " " (U+0020 SPACE)
37503751
* - /
37513752
* - >
37523753
*
37533754
* @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escaped-state
37543755
*/
3755-
if ( preg_match( '~</?script[\t\n\f />]~i', $plaintext_content ) ) {
3756+
if ( preg_match( '~</?script[\t\r\n\f />]~i', $plaintext_content ) ) {
37563757
/*
37573758
* JavaScript can be safely escaped.
37583759
* Non-JavaScript script tags have unknown semantics.
@@ -3761,7 +3762,7 @@ public function set_modifiable_text( string $plaintext_content ): bool {
37613762
*/
37623763
if ( $this->is_javascript_script_tag() ) {
37633764
$plaintext_content = preg_replace_callback(
3764-
'~<(/?)(s)(cript)([\t\n\f />])~i',
3765+
'~<(/?)(s)(cript)([\t\r\n\f />])~i',
37653766
static function ( $matches ) {
37663767
$escaped_s_char = 's' === $matches[2]
37673768
? '\u0073'

0 commit comments

Comments
 (0)