mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Config - don't allow setting key-paths inside of strings, arrays, etc
This commit is contained in:
@@ -1142,8 +1142,8 @@ describe "Config", ->
|
||||
type: 'integer'
|
||||
default: 12
|
||||
|
||||
expect(atom.config.getSchema('foo.baz')).toBeUndefined()
|
||||
expect(atom.config.getSchema('foo.bar.anInt.baz')).toBeUndefined()
|
||||
expect(atom.config.getSchema('foo.baz')).toBe(null)
|
||||
expect(atom.config.getSchema('foo.bar.anInt.baz')).toBe(false)
|
||||
|
||||
it "respects the schema for scoped settings", ->
|
||||
schema =
|
||||
@@ -1380,6 +1380,10 @@ describe "Config", ->
|
||||
expect(atom.config.set('foo.bar.aString', nope: 'nope')).toBe false
|
||||
expect(atom.config.get('foo.bar.aString')).toBe 'ok'
|
||||
|
||||
it 'does not allow setting children of that key-path', ->
|
||||
expect(atom.config.set('foo.bar.aString.something', 123)).toBe false
|
||||
expect(atom.config.get('foo.bar.aString')).toBe 'ok'
|
||||
|
||||
describe 'when the schema has a "maximumLength" key', ->
|
||||
it "trims the string to be no longer than the specified maximum", ->
|
||||
schema =
|
||||
@@ -1438,6 +1442,11 @@ describe "Config", ->
|
||||
atom.config.set 'foo.bar', ['2', '3', '4']
|
||||
expect(atom.config.get('foo.bar')).toEqual [2, 3, 4]
|
||||
|
||||
it 'does not allow setting children of that key-path', ->
|
||||
expect(atom.config.set('foo.bar.child', 123)).toBe false
|
||||
expect(atom.config.set('foo.bar.child.grandchild', 123)).toBe false
|
||||
expect(atom.config.get('foo.bar')).toEqual [1, 2, 3]
|
||||
|
||||
describe 'when the value has a "color" type', ->
|
||||
beforeEach ->
|
||||
schema =
|
||||
|
||||
@@ -665,12 +665,18 @@ class Config
|
||||
#
|
||||
# Returns an {Object} eg. `{type: 'integer', default: 23, minimum: 1}`.
|
||||
# Returns `null` when the keyPath has no schema specified.
|
||||
# Returns `false` when the key-path is not accessible from the root schema.
|
||||
getSchema: (keyPath) ->
|
||||
keys = splitKeyPath(keyPath)
|
||||
schema = @schema
|
||||
for key in keys
|
||||
break unless schema?
|
||||
schema = schema.properties?[key]
|
||||
if schema.type is 'object'
|
||||
childSchema = schema.properties?[key]
|
||||
unless childSchema?
|
||||
return null
|
||||
else
|
||||
return false
|
||||
schema = childSchema
|
||||
schema
|
||||
|
||||
# Extended: Get the {String} path to the config file being used.
|
||||
@@ -948,7 +954,9 @@ class Config
|
||||
catch e
|
||||
undefined
|
||||
else
|
||||
value = @constructor.executeSchemaEnforcers(keyPath, value, schema) if schema = @getSchema(keyPath)
|
||||
if (schema = @getSchema(keyPath))?
|
||||
throw new Error("Illegal key path #{keyPath}") if schema is false
|
||||
value = @constructor.executeSchemaEnforcers(keyPath, value, schema)
|
||||
value
|
||||
|
||||
# When the schema is changed / added, there may be values set in the config
|
||||
|
||||
Reference in New Issue
Block a user