Created
January 30, 2012 21:09
-
-
Save WebReflection/1706722 to your computer and use it in GitHub Desktop.
Fix incorrect behavior of \u2028 and \u2029 characters in JSON.stringify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/ | |
// fix it via RegExp and feature detection | |
if (JSON.stringify("\u2028") == '"\u2028"') { | |
JSON.stringify = function (stringify) { | |
function place(m) { | |
return "\\u202" + (m == "\u2028" ? "8" : "9"); | |
} | |
var re = /\u2028|\u2029/g; | |
return function fixed(data) { | |
return stringify(data).replace(re, place); | |
}; | |
}(JSON.stringify); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment