aboutsummaryrefslogtreecommitdiff
path: root/test/mocha
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-07-23 12:38:21 +0800
committerGitHub <noreply@github.com>2017-07-23 12:38:21 +0800
commit6a5e74b44e65811b2152f72aeec8df3f75457663 (patch)
treed597de5711f351ce1051e91d1e7894d3116f245d /test/mocha
parent54446341eec4c77552d6ea60419ae940f401c16a (diff)
downloadtracifyjs-6a5e74b44e65811b2152f72aeec8df3f75457663.tar.gz
tracifyjs-6a5e74b44e65811b2152f72aeec8df3f75457663.zip
unescape surrogate pairs only (#2246)
fixes #2242
Diffstat (limited to 'test/mocha')
-rw-r--r--test/mocha/string-literal.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/mocha/string-literal.js b/test/mocha/string-literal.js
index fde6db59..d2eb6a80 100644
--- a/test/mocha/string-literal.js
+++ b/test/mocha/string-literal.js
@@ -78,4 +78,41 @@ describe("String literals", function() {
assert.equal(UglifyJS.parse('"use strict";"\\08"').print_to_string(), '"use strict";"\\08";');
assert.equal(UglifyJS.parse('"use strict";"\\09"').print_to_string(), '"use strict";"\\09";');
});
+
+ it("Should not unescape unpaired surrogates", function() {
+ var code = [];
+ for (var i = 0; i <= 0xF; i++) {
+ code.push("\\u000" + i.toString(16));
+ }
+ for (;i <= 0xFF; i++) {
+ code.push("\\u00" + i.toString(16));
+ }
+ for (;i <= 0xFFF; i++) {
+ code.push("\\u0" + i.toString(16));
+ }
+ for (; i <= 0xFFFF; i++) {
+ code.push("\\u" + i.toString(16));
+ }
+ code = '"' + code.join() + '"';
+ var normal = UglifyJS.minify(code, {
+ compress: false,
+ mangle: false,
+ output: {
+ ascii_only: false
+ }
+ });
+ if (normal.error) throw normal.error;
+ assert.ok(code.length > normal.code.length);
+ assert.strictEqual(eval(code), eval(normal.code));
+ var ascii = UglifyJS.minify(code, {
+ compress: false,
+ mangle: false,
+ output: {
+ ascii_only: false
+ }
+ });
+ if (ascii.error) throw ascii.error;
+ assert.ok(code.length > ascii.code.length);
+ assert.strictEqual(eval(code), eval(ascii.code));
+ });
});