Comments (8)
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.
Great point! Thanks.
from json5.
Some data (using V8):
Expression/Source | Result |
---|---|
JSON5.parse('010') | 10 |
JSON.parse('010') | <Syntax error> |
010 | 8 |
(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.
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.
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.
Great catch! I agree with you — let's disallow leading 0's to avoid confusion.
from json5.
I'll update our eval tests to use strict mode (issue #14), and then I'll pull in your commit eab3058cd8. =)
from json5.
Pulled. Thanks again Max!
from json5.
Related Issues (20)
- Module '"node_modules/json5/lib/index"' has no default export HOT 1
- Support Integers outside the range `[-(2**53)+1, (2**53)-1]` HOT 6
- SyntaxError when require()ing JSON5 file in Jest test HOT 1
- Prototype Pollution in JSON5 HOT 11
- json5 latest is now 1.0.2 on npmjs - intentional? HOT 3
- Support Template Literals using backticks? HOT 1
- Provide `exports` config in `packages.json`
- Multiline JSON doesn't multiline HOT 1
- add key property support ? HOT 1
- Add `comma-dangle` option HOT 7
- Online JSON5 Editor(Formatter) is misleading? HOT 2
- Use .substring() instead of the deprecated .substr()
- Cannot stringify "\u0000"
- transitive dependency 'minimist' needs to be updated by rebuilding HOT 1
- question: commented unreachable code HOT 10
- JSON5.stringify() option: `trailingCommas` HOT 3
- Focus on ESNext HOT 1
- CLI should process consecutive JSONs HOT 1
- migrate to ESModules HOT 3
- Missing LICENSE file in the repo of ver 0.4.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json5.