preserve case when `inline_script` (#2991)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 10 Mar 2018 21:11:12 +0000 (05:11 +0800)
committerGitHub <noreply@github.com>
Sat, 10 Mar 2018 21:11:12 +0000 (05:11 +0800)
fixes #2989

README.md
lib/output.js
test/compress/issue-2989.js [new file with mode: 0644]
test/run-tests.js

index 47fabea..1a34ab4 100644 (file)
--- 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.
index cf0b41c..0569ab5 100644 (file)
@@ -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 (file)
index 0000000..c906692
--- /dev/null
@@ -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>"
+}
index dcc7cc1..1b146e8 100755 (executable)
@@ -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();