Loading ...
Sorry, an error occurred while loading the content.

Potential bug in JSON.parse when parsing backslashes?

Expand Messages
  • cosmicrealms
    Code: JSON.parse( T wo ); In Firefox 3.5 and the latest json2.js from json.org this results in a parse exception SyntaxError. Expected: Two It works in: *
    Message 1 of 3 , Jun 29, 2009
    • 0 Attachment
      Code: JSON.parse("\"T\\wo\"");

      In Firefox 3.5 and the latest json2.js from json.org this results in a parse exception SyntaxError.

      Expected: Two

      It works in:
      * The json2.js from json.org from 1-17-2008
      * GWT 1.6's JSON parsing
      * The window.eval snippet from http://www.ietf.org/rfc/rfc4627.txt?number=4627

      Web page to reproduce in Firefox 3.5: http://www.telparia.com/json_backslash_bug_ff35.html

      I filed a bug about it: https://bugzilla.mozilla.org/show_bug.cgi?id=501156

      kbrosnan from #firefox on IRC wanted me to post a message hear about it to find out if it's a bug or by design.

      So it works in some JSON parsers, just not the latest json.org and Firefox 3.5 ones. Is it bad syntax?
    • Douglas Crockford
      ... w is not present in the JSON grammar. An implementation may produce a syntax error. The behavior of Firefox 3.5 is correct.
      Message 2 of 3 , Jun 29, 2009
      • 0 Attachment
        --- In json@yahoogroups.com, "cosmicrealms" <robert@...> wrote:
        >
        > Code: JSON.parse("\"T\\wo\"");
        >
        > In Firefox 3.5 and the latest json2.js from json.org this results in a parse exception SyntaxError.
        >
        > Expected: Two

        \w is not present in the JSON grammar. An implementation may produce a syntax error. The behavior of Firefox 3.5 is correct.
      • John Cowan
        ... The interpretation of string escaping means that T wo is the external representation of a six-character string containing quote-T-
        Message 3 of 3 , Jun 29, 2009
        • 0 Attachment
          cosmicrealms scripsit:
          > Code: JSON.parse("\"T\\wo\"");
          >
          > In Firefox 3.5 and the latest json2.js from json.org this results in
          > a parse exception SyntaxError.

          The interpretation of string escaping means that "\"T\\wo\"" is the
          external representation of a six-character string containing quote-T-
          backslash-w-o-quote. Asking JSON to parse that involves asking it
          to do something with the sequence backslash-w, which is not valid JSON.
          Therefore an error should result.

          --
          Values of beeta will give rise to dom! John Cowan
          (5th/6th edition 'mv' said this if you tried http://www.ccil.org/~cowan
          to rename '.' or '..' entries; see cowan@...
          http://cm.bell-labs.com/cm/cs/who/dmr/odd.html)
        Your message has been successfully submitted and would be delivered to recipients shortly.