Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string evaluated as 'true' for Boolean config #380

Open
hareeshnagaraj opened this issue Oct 11, 2020 · 4 comments
Open

Empty string evaluated as 'true' for Boolean config #380

hareeshnagaraj opened this issue Oct 11, 2020 · 4 comments

Comments

@hareeshnagaraj
Copy link

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?

@dmanjunath
Copy link

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

@theoilie
Copy link

Bump

@KoltesDigital
Copy link

Reproduced on 6.2.4 (latest as of today).

@teadrinker2015
Copy link

Is this a featrue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants