escape illegal js but valid json unicode characters - fixes #247

This commit is contained in:
Sebastian McKenzie 2014-12-13 14:14:47 +11:00
parent 84332da399
commit 13785bddb0

View File

@ -84,8 +84,8 @@ exports.Literal = function (node) {
if (type === "string") { if (type === "string") {
val = JSON.stringify(val); val = JSON.stringify(val);
// escape unicode characters // escape illegal js but valid json unicode characters
val = val.replace(/[\u007f-\uffff]/g, function (c) { val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4); return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
}); });