diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 4c006a24e..f7149e62d 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -645,14 +645,18 @@ describe "Config", -> atom.config.set('foo.bar.aBool', 'FALSE') expect(atom.config.get('foo.bar.aBool')).toBe false atom.config.set('foo.bar.aBool', 1) - expect(atom.config.get('foo.bar.aBool')).toBe true + expect(atom.config.get('foo.bar.aBool')).toBe false atom.config.set('foo.bar.aBool', 0) expect(atom.config.get('foo.bar.aBool')).toBe false atom.config.set('foo.bar.aBool', {}) - expect(atom.config.get('foo.bar.aBool')).toBe true + expect(atom.config.get('foo.bar.aBool')).toBe false atom.config.set('foo.bar.aBool', null) expect(atom.config.get('foo.bar.aBool')).toBe false + # unset + atom.config.set('foo.bar.aBool', undefined) + expect(atom.config.get('foo.bar.aBool')).toBe true + describe 'when the value has an "string" type', -> beforeEach -> schema = @@ -691,7 +695,7 @@ describe "Config", -> atom.config.set 'foo.bar', anInt: '23' nestedObject: - nestedBool: 't' + nestedBool: 'true' expect(atom.config.get('foo.bar')).toEqual anInt: 23 nestedObject: diff --git a/src/config-default-schema.coffee b/src/config-default-schema.coffee index 4dc96d1cd..602e6790a 100644 --- a/src/config-default-schema.coffee +++ b/src/config-default-schema.coffee @@ -100,14 +100,14 @@ module.exports = type: 'object' properties: eol: - type: ['string', 'boolean'] + type: ['boolean', 'string'] default: '\u00ac' space: - type: ['string', 'boolean'] + type: ['boolean', 'string'] default: '\u00b7' tab: - type: ['string', 'boolean'] + type: ['boolean', 'string'] default: '\u00bb' cr: - type: ['string', 'boolean'] + type: ['boolean', 'string'] default: '\u00a4' diff --git a/src/config.coffee b/src/config.coffee index 930d2d419..cdee9f68d 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -154,9 +154,8 @@ pathWatcher = require 'pathwatcher' # # #### boolean # -# Values will be coerced into a Boolean. `'true'` and `'t'` will be coerced into -# `true`. Numbers, arrays, objects, and anything else will be coerced via -# `!!value`. +# Values will be coerced into a Boolean. `'true'` and `'false'` will be coerced into +# a boolean. Numbers, arrays, objects, and anything else will not be coerced. # # ```coffee # config: @@ -647,9 +646,16 @@ Config.addSchemaValidators coercion: (keyPath, value, schema) -> switch typeof value when 'string' - value.toLowerCase() in ['true', 't'] + if value.toLowerCase() in ['true'] + true + else if value.toLowerCase() in ['false'] + false + else + throw new Error("Cannot coerce #{keyPath}, #{JSON.stringify(value)} must be a boolean or the string 'true' or 'false'") + when 'boolean' + value else - !!value + throw new Error("Cannot coerce #{keyPath}, #{JSON.stringify(value)} must be a boolean or the string 'true' or 'false'") 'string': coercion: (keyPath, value, schema) ->