mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
Do not allow infinity in number types
This commit is contained in:
parent
694dd05e7b
commit
ae76bd6c96
@ -532,6 +532,10 @@ describe "Config", ->
|
|||||||
atom.config.set('foo.bar.anInt', '123')
|
atom.config.set('foo.bar.anInt', '123')
|
||||||
expect(atom.config.get('foo.bar.anInt')).toBe 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', ->
|
it 'coerces a float to an int', ->
|
||||||
atom.config.set('foo.bar.anInt', 12.3)
|
atom.config.set('foo.bar.anInt', 12.3)
|
||||||
expect(atom.config.get('foo.bar.anInt')).toBe 12
|
expect(atom.config.get('foo.bar.anInt')).toBe 12
|
||||||
|
@ -393,13 +393,13 @@ Config.addSchemaValidators
|
|||||||
'integer':
|
'integer':
|
||||||
coercion: (keyPath, value, schema) ->
|
coercion: (keyPath, value, schema) ->
|
||||||
value = parseInt(value)
|
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
|
value
|
||||||
|
|
||||||
'number':
|
'number':
|
||||||
coercion: (keyPath, value, schema) ->
|
coercion: (keyPath, value, schema) ->
|
||||||
value = parseFloat(value)
|
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
|
value
|
||||||
|
|
||||||
'boolean':
|
'boolean':
|
||||||
|
Loading…
Reference in New Issue
Block a user