Do not allow infinity in number types

This commit is contained in:
Ben Ogle 2014-09-24 18:08:11 -07:00
parent 694dd05e7b
commit ae76bd6c96
2 changed files with 6 additions and 2 deletions

View File

@ -532,6 +532,10 @@ describe "Config", ->
atom.config.set('foo.bar.anInt', '123')
expect(atom.config.get('foo.bar.anInt')).toBe 123
it 'does not allow infinity', ->
atom.config.set('foo.bar.anInt', Infinity)
expect(atom.config.get('foo.bar.anInt')).toBe 12
it 'coerces a float to an int', ->
atom.config.set('foo.bar.anInt', 12.3)
expect(atom.config.get('foo.bar.anInt')).toBe 12

View File

@ -393,13 +393,13 @@ Config.addSchemaValidators
'integer':
coercion: (keyPath, value, schema) ->
value = parseInt(value)
throw new Error("Cannot set #{keyPath}, #{JSON.stringify(value)} cannot be coerced into an int") if isNaN(value)
throw new Error("Cannot set #{keyPath}, #{JSON.stringify(value)} cannot be coerced into an int") if isNaN(value) or not isFinite(value)
value
'number':
coercion: (keyPath, value, schema) ->
value = parseFloat(value)
throw new Error("Cannot set #{keyPath}, #{JSON.stringify(value)} cannot be coerced into a number") if isNaN(value)
throw new Error("Cannot set #{keyPath}, #{JSON.stringify(value)} cannot be coerced into a number") if isNaN(value) or not isFinite(value)
value
'boolean':