diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 2d8a63794..509d32697 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -602,3 +602,15 @@ describe "Config", -> nestedObject: nestedBool: true + describe 'when the value has an "array" type', -> + beforeEach -> + schema = + type: 'array' + default: [1, 2, 3] + items: + type: 'integer' + atom.config.setSchema('foo.bar', schema) + + it 'converts an array of strings to an array of ints', -> + atom.config.set 'foo.bar', ['2', '3', '4'] + expect(atom.config.get('foo.bar')).toEqual [2, 3, 4] diff --git a/src/config.coffee b/src/config.coffee index 6394a7e77..a41dd5db7 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -427,8 +427,18 @@ Config.addTypeFilters value 'object': - typeCheck: (value, schema) -> + coercion: (value, schema) -> + throw new Error() if typeof value isnt 'object' return value unless schema.properties? for prop, childSchema of schema.properties value[prop] = @executeTypeFilters(value[prop], childSchema) if prop of value value + + 'array': + coercion: (value, schema) -> + throw new Error() unless Array.isArray(value) + itemSchema = schema.items + if itemSchema? + @executeTypeFilters(item, itemSchema) for item in value + else + value