node-convict icon indicating copy to clipboard operation
node-convict copied to clipboard

Empty string evaluated as 'true' for Boolean config

Open hareeshnagaraj opened this issue 4 years ago • 4 comments

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?

hareeshnagaraj avatar Oct 11 '20 23:10 hareeshnagaraj

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

dmanjunath avatar Oct 12 '20 14:10 dmanjunath

Bump

theoilie avatar Mar 22 '22 23:03 theoilie

Reproduced on 6.2.4 (latest as of today).

KoltesDigital avatar Mar 10 '23 09:03 KoltesDigital

Is this a featrue?

teadrinker2015 avatar Apr 01 '23 06:04 teadrinker2015