d3x0r / JSON6

JSON for Humans (ES6)
Other
236 stars 14 forks source link

Object keys #2

Closed stevage closed 6 years ago

stevage commented 6 years ago

Object keys can be unquoted if they do not have ':' or whitespace.

This is weird. It seems to be ok to do:

{my-key: 3}

and even

{my- key: 3}

The doc claims that:

and all of these come from ES5.

You definitely can't do those in ES5.

d3x0r commented 6 years ago

Hmm I really would have expected the second one to generate a failure (the key with a space... and it is a failure of sorts, it returns as 'my-key')

Although something like this would be a success. { my-key\m&m+*|:3}

Errors thrown aren't very good, they need some work...

pushed changes to fix {my- key : 3} .

Did not publish (yet). Want to work on the error throws a little.

stevage commented 6 years ago

Fwiw, it also allowed {my -key: 3} but not {my - key: 3} (haven't retested since your change).

d3x0r commented 6 years ago

yes,.... it would end up allowing any identifier with a single space in it; consuming the space. The only valid character when parsing field name after a space is a colon, or a comment...

summary from https://github.com/d3x0r/JSON6/blob/master/tests/TestObjectKeys.js

{ my- key:3} // fault
{ my -  key:3}  // fault
{ my-key { failure:true}:3} // fault
{ { my-key:3 } }   // fault
{ [ my-key:3 } }   // fault
{ my-key[:3 } }    // fault
{ my-key]:3 } }    // fault

{ 'my  -  key':3}   // valid
{ my-key\\m&m+*|:3}  // valid

{ my-key //test 
   :3}   // valid

{ my-key /*test * / :3}  // valid

In the C version, this is invalid, because it has test for identifier/nonidentifier characters, and only allows identifiers.... I removed that test from javascript version because it was excessively slow.... that and the character table is very large... https://github.com/d3x0r/SACK/blob/master/src/netlib/html5.websocket/json/unicode_non_identifiers.h { my-key\\m&m+*|:3} // valid

jdalton commented 6 years ago

This issue appears to be resolved. Can it be closed?