From b8822b32db7f7a7700cce6f20d905e7e8cc13c45 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 8 Jan 2015 17:11:18 -0800 Subject: [PATCH] Only coerce strings and plain objects --- spec/config-spec.coffee | 9 ++++++--- src/config.coffee | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index c60b88e24..d6d082042 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -1322,9 +1322,6 @@ describe "Config", -> expect(atom.config.get('foo.bar.aColor')).toEqual {red: 0, green: 0, blue: 0, alpha: 1} it 'reverts back to the default value when undefined is passed to set', -> - atom.config.set('foo.bar.aColor', 'rgb(255,255,255)') - expect(atom.config.get('foo.bar.aColor')).toEqual {red: 255, green: 255, blue: 255, alpha: 1} - atom.config.set('foo.bar.aColor', undefined) expect(atom.config.get('foo.bar.aColor')).toEqual {red: 255, green: 255, blue: 255, alpha: 1} @@ -1335,6 +1332,12 @@ describe "Config", -> atom.config.set('foo.bar.aColor', 'nope') expect(atom.config.get('foo.bar.aColor')).toEqual {red: 255, green: 255, blue: 255, alpha: 1} + atom.config.set('foo.bar.aColor', 30) + expect(atom.config.get('foo.bar.aColor')).toEqual {red: 255, green: 255, blue: 255, alpha: 1} + + atom.config.set('foo.bar.aColor', false) + expect(atom.config.get('foo.bar.aColor')).toEqual {red: 255, green: 255, blue: 255, alpha: 1} + describe 'when the `enum` key is used', -> beforeEach -> schema = diff --git a/src/config.coffee b/src/config.coffee index 17c697930..e44fc4491 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -1121,9 +1121,11 @@ Config.addSchemaEnforcers 'color': coerce: (keyPath, value, schema) -> - try - color = new Color(value) - catch error + if isPlainObject(value) or typeof value is 'string' + try + color = new Color(value) + + unless color? throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} cannot be coerced into a color") value =