mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
explain the rationale for the chosen escaping implemenation in a comment (#24389)
This commit is contained in:
+13
-4
@@ -83,16 +83,25 @@ const startScriptSrc = stringToPrecomputedChunk('<script src="');
|
||||
const startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
|
||||
const endAsyncScript = stringToPrecomputedChunk('" async=""></script>');
|
||||
|
||||
const scriptRegex = /(<\/|<)(s)(cript)/gi;
|
||||
const scriptReplacer = (match, prefix, s, suffix) =>
|
||||
`${prefix}${s === 's' ? '\\u0073' : '\\u0053'}${suffix}`;
|
||||
|
||||
/**
|
||||
* This escaping function is designed to work with bootstrapScriptContent only.
|
||||
* because we know we are escaping the entire script. We can avoid for instance
|
||||
* escaping html comment string sequences that are valid javascript as well because
|
||||
* if there are no sebsequent <script sequences the html parser will never enter
|
||||
* script data double escaped state (see: https://www.w3.org/TR/html53/syntax.html#script-data-double-escaped-state)
|
||||
*
|
||||
* While untrusted script content should be made safe before using this api it will
|
||||
* ensure that the script cannot be early terminated or never terminated state
|
||||
*/
|
||||
function escapeBootstrapScriptContent(scriptText) {
|
||||
if (__DEV__) {
|
||||
checkHtmlStringCoercion(scriptText);
|
||||
}
|
||||
return ('' + scriptText).replace(scriptRegex, scriptReplacer);
|
||||
}
|
||||
const scriptRegex = /(<\/|<)(s)(cript)/gi;
|
||||
const scriptReplacer = (match, prefix, s, suffix) =>
|
||||
`${prefix}${s === 's' ? '\\u0073' : '\\u0053'}${suffix}`;
|
||||
|
||||
// Allows us to keep track of what we've already written so we can refer back to it.
|
||||
export function createResponseState(
|
||||
|
||||
Reference in New Issue
Block a user