From 07bb7262d02547cef5ffaca71d49c86640a1df15 Mon Sep 17 00:00:00 2001 From: kzc Date: Thu, 24 Mar 2016 11:51:54 -0400 Subject: 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 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/output.js') diff --git a/lib/output.js b/lib/output.js index a8c45a0f..a59066fc 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"; } -- cgit v1.2.3