escape unicode characters - fixes #154
This commit is contained in:
@@ -74,7 +74,16 @@ exports.Literal = function (node) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "boolean" || type === "number" || type === "string") {
|
||||
if (type === "string") {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape unicode characters
|
||||
val = val.replace(/[\u007f-\uffff]/g, function(c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
} else if (type === "boolean" || type === "number") {
|
||||
this.push(JSON.stringify(val));
|
||||
} else if (node.regex) {
|
||||
this.push("/" + node.regex.pattern + "/" + node.regex.flags);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
5;
|
||||
"foobar";
|
||||
"\n\r\u2028\u2029";
|
||||
/foobar/g;
|
||||
null;
|
||||
true;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
5;
|
||||
"foobar";
|
||||
"\n\r\u2028\u2029";
|
||||
/foobar/g;
|
||||
null;
|
||||
true;
|
||||
|
||||
Reference in New Issue
Block a user