Better escaping of null characters.
If a null character isn't followed by a digit, then it should be safe to escape it using the shorter sequence "\0" instead of "\x00".
This commit is contained in:
parent
253c7c2325
commit
46cd2c1895
|
|
@ -84,7 +84,7 @@ function OutputStream(options) {
|
||||||
|
|
||||||
function make_string(str) {
|
function make_string(str) {
|
||||||
var dq = 0, sq = 0;
|
var dq = 0, sq = 0;
|
||||||
str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029\0]/g, function(s){
|
str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029\0]/g, function(s, i){
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case "\\": return "\\\\";
|
case "\\": return "\\\\";
|
||||||
case "\b": return "\\b";
|
case "\b": return "\\b";
|
||||||
|
|
@ -95,7 +95,9 @@ function OutputStream(options) {
|
||||||
case "\u2029": return "\\u2029";
|
case "\u2029": return "\\u2029";
|
||||||
case '"': ++dq; return '"';
|
case '"': ++dq; return '"';
|
||||||
case "'": ++sq; return "'";
|
case "'": ++sq; return "'";
|
||||||
case "\0": return "\\x00";
|
case "\0":
|
||||||
|
var next = s.charCodeAt(i + 1);
|
||||||
|
return 48 <= next && next <= 57 ? "\\x00" : "\\0";
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user