mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Adhere to the schemas when loading the user’s config
This commit is contained in:
@@ -699,6 +699,26 @@ describe "Config", ->
|
||||
expect(atom.config.get("foo.bar")).toBe 'baz'
|
||||
expect(atom.config.get("foo.bar", scope: ['.source.ruby'])).toBe 'more-specific'
|
||||
|
||||
describe "when the config file does not conform to the schema", ->
|
||||
beforeEach ->
|
||||
fs.writeFileSync atom.config.configFilePath, """
|
||||
'*':
|
||||
foo:
|
||||
bar: 'omg'
|
||||
int: 'baz'
|
||||
'.source.ruby':
|
||||
foo:
|
||||
bar: 'scoped'
|
||||
int: 'nope'
|
||||
"""
|
||||
|
||||
it "validates and does not load the incorrect values", ->
|
||||
atom.config.loadUserConfig()
|
||||
expect(atom.config.get("foo.int")).toBe 12
|
||||
expect(atom.config.get("foo.bar")).toBe 'omg'
|
||||
expect(atom.config.get("foo.int", scope: ['.source.ruby'])).toBe 12
|
||||
expect(atom.config.get("foo.bar", scope: ['.source.ruby'])).toBe 'scoped'
|
||||
|
||||
describe "when the config file contains valid cson", ->
|
||||
beforeEach ->
|
||||
fs.writeFileSync(atom.config.configFilePath, "foo: bar: 'baz'")
|
||||
|
||||
@@ -1032,8 +1032,19 @@ class Config
|
||||
|
||||
resetUserScopedSettings: (newScopedSettings) ->
|
||||
source = @getUserConfigPath()
|
||||
priority = @priorityForSource(source)
|
||||
@scopedSettingsStore.removePropertiesForSource(source)
|
||||
@scopedSettingsStore.addProperties(source, newScopedSettings, priority: @priorityForSource(source))
|
||||
|
||||
for scopeSelector, settings of newScopedSettings
|
||||
validatedSettings = {}
|
||||
try
|
||||
settings = withoutEmptyObjects(@makeValueConformToSchema(null, settings))
|
||||
validatedSettings[scopeSelector] = settings
|
||||
catch e
|
||||
;
|
||||
|
||||
@scopedSettingsStore.addProperties(source, validatedSettings, {priority}) if validatedSettings[scopeSelector]
|
||||
|
||||
@emitChangeEvent()
|
||||
|
||||
addScopedSettings: (source, selector, value, options) ->
|
||||
|
||||
Reference in New Issue
Block a user