aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/unicode.js40
-rw-r--r--test/mocha/string-literal.js37
2 files changed, 77 insertions, 0 deletions
diff --git a/test/compress/unicode.js b/test/compress/unicode.js
index 9fb9ab8c..4dbc197c 100644
--- a/test/compress/unicode.js
+++ b/test/compress/unicode.js
@@ -15,3 +15,43 @@ unicode_parse_variables: {
var l০ = 3;
}
}
+
+issue_2242_1: {
+ beautify = {
+ ascii_only: false,
+ }
+ input: {
+ console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
+ }
+ expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");'
+}
+
+issue_2242_2: {
+ beautify = {
+ ascii_only: true,
+ }
+ input: {
+ console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00");
+ }
+ expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");'
+}
+
+issue_2242_3: {
+ options = {
+ evaluate: false,
+ }
+ input: {
+ console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
+ }
+ expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");'
+}
+
+issue_2242_4: {
+ options = {
+ evaluate: true,
+ }
+ input: {
+ console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00");
+ }
+ expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");'
+}
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));
+ });
});