Uh oh!
There was an error while loading. Please reload this page.
Escape bootstrapScriptContent for javascript embedding into HTML - #24385
Conversation
Comparing: 726ba80...b8e4253 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Uh oh!
There was an error while loading. Please reload this page.
sebmarkbage
left a comment
There was a problem hiding this comment.
Some nits but the essence looks good.
Uh oh!
There was an error while loading. Please reload this page.
| const scriptRegex = /(<\/|<)(s)(cript)/gi; | ||
| const scriptReplacer = (match, prefix, s, suffix) => | ||
| `${prefix}${substitutions[s]}${suffix}`; |
There was a problem hiding this comment.
Let's make this an inline condition instead of going through a whole hidden class check and fake-map look up.
There was a problem hiding this comment.
I meant s === 's' ? '\\u0073' : '\\u0053'
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The previous escape was for Text into HTML and breaks script contents. The new escaping ensures that the script contents cannot prematurely close the host script tag by escaping script open and close string sequences using a unicode escape substitution.
the escaping of this function does is tailored to the specific use case of how bootstrapScriptContent is currently set up and having it be a module suggests it is meant for a more general than it has been considered for. Additionally the tests were redone to focus on practical implications for what is and is not escaped
| const scriptReplacer = (match, prefix, s, suffix) => | ||
| `${prefix}${s === 's' ? '\\u0073' : '\\u0053'}${suffix}`; | ||
| function escapeBootstrapScriptContent(scriptText) { |
There was a problem hiding this comment.
Maybe a leave a comment with the rationale and clarifying that this only works if the whole content is encoded and if it's an actual JS script tag, and doesn't work for attributes or CSS.
…ct#24385) The previous escape was for Text into HTML and breaks script contents. The new escaping ensures that the script contents cannot prematurely close the host script tag by escaping script open and close string sequences using a unicode escape substitution.
The previous escape was for Text into HTML and breaks script contents. The new escaping ensures that the script contents cannot prematurely close the host script tag by escaping script open and close string sequences using a unicode escape substitution.
closes: #23063