String type must be strict.

It makes sense to coerce from more general -> more specific data types.
eg. string -> int, etc. But coercing the other way is problematic
in the case of chaining because the more general type will swallow the
specific type. eg. Setting `false` on type: [‘string’, ‘boolean’] will 
coerce the boolean to a string, and will never allow the value to be
a boolean.
This commit is contained in:
Ben Ogle
2014-09-29 15:50:54 -07:00
parent 9808264b7f
commit b54deccfae
2 changed files with 11 additions and 13 deletions

View File

@@ -667,12 +667,10 @@ Config.addSchemaEnforcers
throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} must be a boolean or the string 'true' or 'false'")
'string':
coerce: (keyPath, value, schema) ->
switch typeof value
when 'number', 'string'
value.toString()
else
throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} must be a string or number")
validate: (keyPath, value, schema) ->
unless typeof value is 'string'
throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} must be a string")
value
'null':
# null sort of isnt supported. It will just unset in this case