Code Monkey home page Code Monkey logo

Comments (8)

MaxNanasy avatar MaxNanasy commented on September 25, 2024

I think disallowing octal literals would be justified, since ES5 disallows octal literals in strict mode (see http://es5.github.com/#B.1).

from json5.

aseemk avatar aseemk commented on September 25, 2024

Great point! Thanks.

from json5.

MaxNanasy avatar MaxNanasy commented on September 25, 2024

Some data (using V8):

Expression/SourceResult
JSON5.parse('010')10
JSON.parse('010')<Syntax error>
0108
(function () { "use strict"; return 010; })()<Syntax error>
([http://json.org]).parse('010')<Syntax error>

I feel like JSON5.parse('010') should throw a syntax error.
Also see https://mail.mozilla.org/pipermail/es-discuss/2009-June/009428.html, which discusses whether or not to validate octalish literals when parsing JSON and seems to reach the same consensus.

from json5.

aseemk avatar aseemk commented on September 25, 2024

Great point!

Looking at your hexadecimal patch, this should be straightforward to do, too, yeah? When we start with a 0, if the next character is a digit, throw an error. WDYT?

It might be nice to look into exactly what the other implementations do, to see if there are edge cases we need to account for.

Sorry, I'm completely busy in my day job right now, but I hope to take a look into this and other issues soon. Thanks for all the help!

from json5.

MaxNanasy avatar MaxNanasy commented on September 25, 2024

In strict mode, the ES5 spec, SpiderMonkey, and V8 disallow octal literals such as 07. However, in strict mode, the ES5 spec and SpiderMonkey disallow, but V8 allows, noctal literals (so-called because they have a leading 0 but non-octal digits) such as 08 or 078, which it interprets as decimal. Do you think that JSON5 should support noctal literals? I do not.

from json5.

aseemk avatar aseemk commented on September 25, 2024

Great catch! I agree with you — let's disallow leading 0's to avoid confusion.

from json5.

aseemk avatar aseemk commented on September 25, 2024

I'll update our eval tests to use strict mode (issue #14), and then I'll pull in your commit eab3058cd8. =)

from json5.

aseemk avatar aseemk commented on September 25, 2024

Pulled. Thanks again Max!

from json5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.