From ae76bd6c96e766d2ecc6d328c0d52363dd1eff59 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 24 Sep 2014 18:08:11 -0700 Subject: [PATCH] Do not allow infinity in number types --- spec/config-spec.coffee | 4 ++++ src/config.coffee | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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':