mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Only coerce strings and plain objects
This commit is contained in:
parent
8c39818670
commit
b8822b32db
@ -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 =
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user