Only coerce strings and plain objects

This commit is contained in:
Kevin Sawicki 2015-01-08 17:11:18 -08:00
parent 8c39818670
commit b8822b32db
2 changed files with 11 additions and 6 deletions

View File

@ -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 =

View File

@ -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 =