bevry / cson

CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.
Other
1.34k stars 55 forks source link

parseCSONString passes JSON #71

Closed idleberg closed 8 years ago

idleberg commented 8 years ago

I noticed that parseCSONString will accept passed JSON

CSON.parseCSONString({"JSON": "not CSON"})

I'd expect this to throw an error, otherwise what would be the difference between parseString and parseCSONString?

balupton commented 8 years ago

JSON is valid CSON

balupton commented 8 years ago

Or is the issue more that it is not a string being passed in your code sample?

idleberg commented 8 years ago

I use your package for an Atom plugin and since I don't want to rely on the scope alone (which Atom determines by file extension), I wanted to use parseCSONString to test whether I'm working with CSON or JSON.

balupton commented 8 years ago

Well, as JSON is a subset of CSON, it means JSON is valid CSON, so using the parse CSON methods for testing JSON won't work, as JSON is valid CSON. However, CSON is not a subset of JSON, which means CSON is not valid CSON. Inverse your try catch and you'll be good.

idleberg commented 8 years ago

OK, thanks!