Skip to content

Commit

Permalink
preserve case when inline_script (#2991)
Browse files Browse the repository at this point in the history
fixes #2989
  • Loading branch information
alexlamsl committed Mar 10, 2018
1 parent 7e00a12 commit fc6ebd0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -837,8 +837,8 @@ can pass additional arguments that control the code output:

- `indent_start` (default `0`) -- prefix all lines by that many spaces

- `inline_script` (default `false`) -- escape the slash in occurrences of
`</script` in strings
- `inline_script` (default `true`) -- escape HTML comments and the slash in
occurrences of `</script>` in strings

- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
quotes from property names in object literals.
Expand Down
2 changes: 1 addition & 1 deletion lib/output.js
Expand Up @@ -178,7 +178,7 @@ function OutputStream(options) {
function encode_string(str, quote) {
var ret = make_string(str, quote);
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(/--\x3e/g, "--\\x3e");
}
Expand Down
21 changes: 21 additions & 0 deletions test/compress/issue-2989.js
@@ -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>"
}
1 change: 0 additions & 1 deletion test/run-tests.js
Expand Up @@ -343,7 +343,6 @@ function parse_test(file) {
}

function make_code(ast, options) {
options.inline_script = true;
var stream = U.OutputStream(options);
ast.print(stream);
return stream.get();
Expand Down

0 comments on commit fc6ebd0

Please sign in to comment.