aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-03-11 05:11:12 +0800
committerGitHub <noreply@github.com>2018-03-11 05:11:12 +0800
commitfc6ebd04a59024dfd3b40b43825a007c62bac2b3 (patch)
treec64055b5a80e2374f47b841754d051348db594d3
parent7e00a1274139e65ad82d8938b816602aedb5d318 (diff)
downloadtracifyjs-fc6ebd04a59024dfd3b40b43825a007c62bac2b3.tar.gz
tracifyjs-fc6ebd04a59024dfd3b40b43825a007c62bac2b3.zip
preserve case when `inline_script` (#2991)
fixes #2989
-rw-r--r--README.md4
-rw-r--r--lib/output.js2
-rw-r--r--test/compress/issue-2989.js21
-rwxr-xr-xtest/run-tests.js1
4 files changed, 24 insertions, 4 deletions
diff --git a/README.md b/README.md
index 47fabea1..1a34ab4e 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/lib/output.js b/lib/output.js
index cf0b41cd..0569ab53 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -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");
}
diff --git a/test/compress/issue-2989.js b/test/compress/issue-2989.js
new file mode 100644
index 00000000..c9066921
--- /dev/null
+++ b/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>"
+}
diff --git a/test/run-tests.js b/test/run-tests.js
index dcc7cc1e..1b146e86 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -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();