diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 3264a9fd9..6845b0c89 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -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 diff --git a/src/config.coffee b/src/config.coffee index 502cb9ed5..698d86ddc 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -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':