function isJSON() {
var str = this;
if (str.blank()) return false;
str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
}
If I send a JSON { 'str': '<p>This is a line with \n linefeed</p>' } I do get
an error. The same is, if the JSON is encoded to { 'str': '<p>This is a line
with %0A linefeed</p>' }.
I need to delete the linefeed or I need to replace to '<br />'.
I do not understand the regular expression above, because I want avoid to use
other chars, which results in errors.
Manfred
--
http://www.comparat.de
http://www.athesios.de
http://twitter.com/COMPARAT
I do send "\\n" or "<br />" from server to the browser.
But my question was: which chars need to be escaped too? I can see "\r", "\f"
and "\t". But the other RegExp rule I do not understand.
Manfred
I only want, that I did not run into new problems later, and want to
understand, what isJSON() does. So I do not understand the regular expression
until now:
str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
I there a documentation to this function? I would like to read something like
this:
"isJSON does not accept \n chars and @ chars in a string."
It is for security and that is fine. But it is not fine, if my customer find a
problem later.
Thank you in advance
Manfred