javascript - JSON.stringify and "\u2028\u2029" check? -


sometimes see in view source page ( html view source) code:

if (json.stringify(["\u2028\u2029"]) === '["\u2028\u2029"]') json.stringify = function (a) {     var b = /\u2028/g,         c = /\u2029/g;     return function (d, e, f) {         var g = a.call(this, d, e, f);         if (g) {             if (-1 < g.indexof('\u2028')) g = g.replace(b, '\\u2028');             if (-1 < g.indexof('\u2029')) g = g.replace(c, '\\u2029');         }         return g;     }; }(json.stringify); 
  • what problem json.stringify(["\u2028\u2029"]) needs checked ?

additional info :

  • json.stringify(["\u2028\u2029"]) value "["

"]"
  • '["\u2028\u2029"]' value "["

"]"

i thought might security feature. fileformat.info 2028 , 2029 have banner stating

do not use character in domain names. browsers blacklisting because of potential phishing.

but turns out line , paragraph separators \u2028 , \u2029 respectively treated new line in es5 javascript.

from http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/

\u2028 , \u2029 characters can break entire json feeds since string contain new line , javascript parser bail out

so seeing patch json.stringify. see node.js javascript-stringify

edit: yes, modern browsers' built-in json object should take care of correctly. can't find links actual source though. chromium code search doesn't mention bugs warrant adding workaround manually. looks firefox 3.5 first version have native json support, not entirely bug-free though. ie8 supports too. unnecessary patch, assuming browsers have implemented specification correctly.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -