Skip to content

Commit 4f6d9d3

Browse files
committed
Improve script tag check
1 parent 4b9aa42 commit 4f6d9d3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,22 @@ function wp_print_scripts( $handles = false ) {
130130
function wp_add_inline_script( $handle, $data, $position = 'after' ) {
131131
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
132132

133-
if ( false !== stripos( $data, '<script>' ) ) {
134-
135-
// The script tag should be the only token, otherwise it's not a <script> tag.
133+
/*
134+
* Check whether the script data appears to be enclosed in an HTML <script> tag.
135+
*/
136+
if (
137+
strlen( $data ) >= 17 &&
138+
0 === substr_compare( $data, '<script', 0, 7, true ) &&
139+
(
140+
"\t" === $data[7] ||
141+
"\n" === $data[7] ||
142+
"\f" === $data[7] ||
143+
' ' === $data[7] ||
144+
'/' === $data[7] ||
145+
'>' === $data[7]
146+
)
147+
) {
148+
// Try to parse and extract the script contents.
136149
$processor = new WP_HTML_Tag_Processor( $data );
137150
$processor->next_token();
138151
if ( $processor->get_tag() === 'SCRIPT' ) {

0 commit comments

Comments
 (0)