aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2016-03-24 11:51:54 -0400
committerkzc <zaxxon2011@gmail.com>2016-03-24 11:51:54 -0400
commit07bb7262d02547cef5ffaca71d49c86640a1df15 (patch)
tree00e9c98a271bed172168333e843d007d2a681afb /lib/output.js
parentee6c9fabb7dc00b8bbc9e60859767acc585cd0fa (diff)
downloadtracifyjs-07bb7262d02547cef5ffaca71d49c86640a1df15.tar.gz
tracifyjs-07bb7262d02547cef5ffaca71d49c86640a1df15.zip
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.
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js11
1 files changed, 6 insertions, 5 deletions
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";
}