cson-parser icon indicating copy to clipboard operation
cson-parser copied to clipboard

Support Infinity

Open kevinsawicki opened this issue 11 years ago • 6 comments

Unclear if this was intentional or not but is Infinity supported?

It seems to oddly hang when parsed:

> coffee
coffee> c = require 'cson-safe'
{ stringify: [Function], parse: [Function] }
coffee> c.parse('Infinity')
... 

kevinsawicki avatar Mar 21 '14 00:03 kevinsawicki

Since we allow 1/0, -1/0 it might be good to also support Infinity for consistency. Other pro arguments include that JSON can include Infinity (though it's kind of messy since it doesn't serialize properly):

coffee> JSON.parse('{ "x": 1.0e+1024 }')
{ x: Infinity }
coffee> JSON.parse('{ "x": -1.0e+1024 }')
{ x: -Infinity }
coffee> JSON.stringify(JSON.parse('{ "x": -1.0e+1024 }'))
'{"x":null}'

Related to this would be the question if NaN should be supported. I can't come up with a way to produce the same value in JSON, so I'm tending to make it fail (but definitely adding a test for it as well).

hybrist avatar Mar 21 '14 00:03 hybrist

Just curious, does the snippet I provided hang for you as well when run?

kevinsawicki avatar Mar 21 '14 00:03 kevinsawicki

Was expecting it to hang, based on your description - but (from inside this project):

> coffee                                         
coffee> require('./').parse('Infinity')
SyntaxError: Syntax error on line 1, column 1: Unexpected Identifier

hybrist avatar Mar 21 '14 00:03 hybrist

Cool, thanks for letting me know, must be something else going on.

kevinsawicki avatar Mar 21 '14 00:03 kevinsawicki

Adding a test for now to have it covered (#3). The test passes on my machine (0.10.24) and on travis (0.10.25, 0.8.26, 0.11.11).

hybrist avatar Mar 21 '14 01:03 hybrist

@kevinsawicki it doesn’t “hang” for you—you’ve run into https://github.com/jashkenas/coffee-script/issues/3388.

lydell avatar May 25 '14 16:05 lydell