@@ -83,16 +83,25 @@ const startScriptSrc = stringToPrecomputedChunk('<script src="');
83
83
const startModuleSrc = stringToPrecomputedChunk ( '<script type="module" src="' ) ;
84
84
const endAsyncScript = stringToPrecomputedChunk ( '" async=""></script>' ) ;
85
85
86
- const scriptRegex = / ( < \/ | < ) ( s ) ( c r i p t ) / gi;
87
- const scriptReplacer = ( match , prefix , s , suffix ) =>
88
- `${ prefix } ${ s === 's' ? '\\u0073' : '\\u0053' } ${ suffix } ` ;
89
-
86
+ /**
87
+ * This escaping function is designed to work with bootstrapScriptContent only.
88
+ * because we know we are escaping the entire script. We can avoid for instance
89
+ * escaping html comment string sequences that are valid javascript as well because
90
+ * if there are no sebsequent <script sequences the html parser will never enter
91
+ * script data double escaped state (see: https://www.w3.org/TR/html53/syntax.html#script-data-double-escaped-state)
92
+ *
93
+ * While untrusted script content should be made safe before using this api it will
94
+ * ensure that the script cannot be early terminated or never terminated state
95
+ */
90
96
function escapeBootstrapScriptContent ( scriptText ) {
91
97
if ( __DEV__ ) {
92
98
checkHtmlStringCoercion ( scriptText ) ;
93
99
}
94
100
return ( '' + scriptText ) . replace ( scriptRegex , scriptReplacer ) ;
95
101
}
102
+ const scriptRegex = / ( < \/ | < ) ( s ) ( c r i p t ) / gi;
103
+ const scriptReplacer = ( match , prefix , s , suffix ) =>
104
+ `${ prefix } ${ s === 's' ? '\\u0073' : '\\u0053' } ${ suffix } ` ;
96
105
97
106
// Allows us to keep track of what we've already written so we can refer back to it.
98
107
export function createResponseState (
0 commit comments