node-convict
node-convict copied to clipboard
Empty string evaluated as 'true' for Boolean config
Given a config with the following definition:
myTestConfig: {
format: Boolean,
env: 'myTestConfig',
default: false
}
An environment variable set to myTestConfig=''
is evaluated as true. Consistently reproduced with 5.1.0
I was able to work around this by adding the following custom format:
convict.addFormat({
name: 'BooleanCustom',
validate: function (val) {
return (typeof val === "boolean") || (typeof val === "string")
},
coerce: function (val) {
return Boolean(val)
}
})
^The above seems unnecessary for what I expected to be default behavior.
Are empty strings expected to evaluate to Boolean true with node-convict?
Reproduced on 6.0.0 as well. Empty string returns true whereas in javascript empty string is treated as false.
https://runkit.com/5f846dc85d54e8001aa64b70/5f846dc95a8dee001ab902be
Bump
Reproduced on 6.2.4 (latest as of today).
Is this a featrue?