Escape null characters as \0 unless followed by 0-7.

This commit is contained in:
David Bau
2013-12-23 16:05:04 +00:00
committed by Richard van Velzen
parent ea31da2455
commit f99b7b630d
3 changed files with 14 additions and 6 deletions

View File

@@ -88,7 +88,8 @@ function OutputStream(options) {
function make_string(str, quote) {
var dq = 0, sq = 0;
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s){
str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g,
function(s, i){
switch (s) {
case '"': ++dq; return '"';
case "'": ++sq; return "'";
@@ -101,8 +102,9 @@ function OutputStream(options) {
case "\x0B": return options.screw_ie8 ? "\\v" : "\\x0B";
case "\u2028": return "\\u2028";
case "\u2029": return "\\u2029";
case "\0": return "\\x00";
case "\ufeff": return "\\ufeff";
case "\0":
return /[0-7]/.test(str.charAt(i+1)) ? "\\x00" : "\\0";
}
return s;
});