From: Alex Lam S.L Date: Sat, 10 Mar 2018 21:11:12 +0000 (+0800) Subject: preserve case when `inline_script` (#2991) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=fc6ebd04a59024dfd3b40b43825a007c62bac2b3;p=UglifyJS.git preserve case when `inline_script` (#2991) fixes #2989 --- 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 - `` 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(""); + } + expect_exact: 'console.log("");' + expect_stdout: "" +} + +inline_script_on: { + beautify = { + inline_script: true, + } + input: { + console.log(""); + } + expect_exact: 'console.log("<\\/sCrIpT>");' + expect_stdout: "" +} 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();