preserve case when inline_script (#2991)

fixes #2989
This commit is contained in:
Alex Lam S.L
2018-03-11 05:11:12 +08:00
committed by GitHub
parent 7e00a12741
commit fc6ebd04a5
4 changed files with 24 additions and 4 deletions

View File

@@ -837,8 +837,8 @@ can pass additional arguments that control the code output:
- `indent_start` (default `0`) -- prefix all lines by that many spaces - `indent_start` (default `0`) -- prefix all lines by that many spaces
- `inline_script` (default `false`) -- escape the slash in occurrences of - `inline_script` (default `true`) -- escape HTML comments and the slash in
`</script` in strings occurrences of `</script>` in strings
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping - `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
quotes from property names in object literals. quotes from property names in object literals.

View File

@@ -178,7 +178,7 @@ function OutputStream(options) {
function encode_string(str, quote) { function encode_string(str, quote) {
var ret = make_string(str, quote); var ret = make_string(str, quote);
if (options.inline_script) { if (options.inline_script) {
ret = ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi, "<\\/script$1"); ret = ret.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi, "<\\/$1$2");
ret = ret.replace(/\x3c!--/g, "\\x3c!--"); ret = ret.replace(/\x3c!--/g, "\\x3c!--");
ret = ret.replace(/--\x3e/g, "--\\x3e"); ret = ret.replace(/--\x3e/g, "--\\x3e");
} }

View File

@@ -0,0 +1,21 @@
inline_script_off: {
beautify = {
inline_script: false,
}
input: {
console.log("</sCrIpT>");
}
expect_exact: 'console.log("</sCrIpT>");'
expect_stdout: "</sCrIpT>"
}
inline_script_on: {
beautify = {
inline_script: true,
}
input: {
console.log("</sCrIpT>");
}
expect_exact: 'console.log("<\\/sCrIpT>");'
expect_stdout: "</sCrIpT>"
}

View File

@@ -343,7 +343,6 @@ function parse_test(file) {
} }
function make_code(ast, options) { function make_code(ast, options) {
options.inline_script = true;
var stream = U.OutputStream(options); var stream = U.OutputStream(options);
ast.print(stream); ast.print(stream);
return stream.get(); return stream.get();