[Pkg-javascript-commits] [uglifyjs] 125/190: Escape all ASCII control characters within strings when using ascii_only.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 07bb7262d02547cef5ffaca71d49c86640a1df15
Author: kzc <zaxxon2011 at gmail.com>
Date:   Thu Mar 24 11:51:54 2016 -0400

    Escape all ASCII control characters within strings when using ascii_only.
    
    Fixes #1017.
    
    Tab characters within strings are now output as `\t` in all output modes.
---
 lib/output.js          | 11 ++++++-----
 test/compress/ascii.js | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index a8c45a0..a59066f 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -74,7 +74,7 @@ function OutputStream(options) {
     var OUTPUT = "";
 
     function to_ascii(str, identifier) {
-        return str.replace(/[\u0080-\uffff]/g, function(ch) {
+        return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
             var code = ch.charCodeAt(0).toString(16);
             if (code.length <= 2 && !identifier) {
                 while (code.length < 2) code = "0" + code;
@@ -90,16 +90,17 @@ function OutputStream(options) {
         var dq = 0, sq = 0;
         str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s){
             switch (s) {
+              case '"': ++dq; return '"';
+              case "'": ++sq; return "'";
               case "\\": return "\\\\";
-              case "\b": return "\\b";
-              case "\f": return "\\f";
               case "\n": return "\\n";
               case "\r": return "\\r";
+              case "\t": return "\\t";
+              case "\b": return "\\b";
+              case "\f": return "\\f";
               case "\x0B": return options.screw_ie8 ? "\\v" : "\\x0B";
               case "\u2028": return "\\u2028";
               case "\u2029": return "\\u2029";
-              case '"': ++dq; return '"';
-              case "'": ++sq; return "'";
               case "\0": return "\\x00";
               case "\ufeff": return "\\ufeff";
             }
diff --git a/test/compress/ascii.js b/test/compress/ascii.js
new file mode 100644
index 0000000..5c6b3b8
--- /dev/null
+++ b/test/compress/ascii.js
@@ -0,0 +1,32 @@
+ascii_only_true: {
+    options = {}
+    beautify = {
+        ascii_only : true,
+        beautify   : false,
+    }
+    input: {
+        function f() {
+            return "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
+                   "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
+                   "\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
+        }
+    }
+    expect_exact: 'function f(){return"\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\b\\t\\n\\x0B\\f\\r\\x0e\\x0f"+"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"+\' !"# ... }~\\x7f\\x80\\x81 ... \\xfe\\xff\\u0fff\\uffff\'}'
+}
+
+ascii_only_false: {
+    options = {}
+    beautify = {
+        ascii_only : false,
+        beautify   : false,
+    }
+    input: {
+        function f() {
+            return "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
+                   "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
+                   "\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
+        }
+    }
+    expect_exact: 'function f(){return"\\x00\x01\x02\x03\x04\x05\x06\x07\\b\\t\\n\\x0B\\f\\r\x0e\x0f"+"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+\' !"# ... }~\x7f\x80\x81 ... \xfe\xff\u0fff\uffff\'}'
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list