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

.get defaultValue is bypassed when env was set to undefined #42

Closed
jcppman opened this issue Jan 23, 2025 · 5 comments
Closed

.get defaultValue is bypassed when env was set to undefined #42

jcppman opened this issue Jan 23, 2025 · 5 comments
Labels

Comments

@jcppman
Copy link

jcppman commented Jan 23, 2025

Edited/20250129

  • added reproduction repo
  • modified reproduction steps

Package version

6.1.1

Describe the bug

When an env variable is cleared by executing env.set("MY_VAR", undefined) or process.env.MY_VAR = undefined, env.get("MY_VAR", "DEFAULT") will return undefined.

This is kind of a rare usage but it is very useful for testing how adonis configuration react to env var changes.

Reproducing steps

  1. ensure originally process.env.MY_VAR is undefined
  2. env.set('MY_VAR', 'new value')
  3. env.set('MY_VAR', undefined)
  4. assert(env.get('MY_VAR', "DEFAULT"))

Expected behavior

env.get("MY_VAR", "DEFAULT") should still return "DEFAULT"

Actual behavior

env.get("MY_VAR", "DEFAULT") returns undefined

Reproduction repo

https://github.com/jcppman/adonis-env/tree/reprod-env-default

@thetutlage
Copy link
Member

Can you please create failing test for this? Because as per this logic https://github.com/adonisjs/env/blob/6.x/src/env.ts#L121-L124 the default value should be returned.

@jcppman
Copy link
Author

jcppman commented Jan 29, 2025

please refer to the testcase added here

jcppman@246e08b

jcppman added a commit to jcppman/adonis-env that referenced this issue Jan 29, 2025
jcppman added a commit to jcppman/adonis-env that referenced this issue Jan 29, 2025
jcppman added a commit to jcppman/adonis-env that referenced this issue Jan 29, 2025
resolves adonisjs#42:

When an env value was undefined and set to a value, then manually set to
undefined again, env.get('VAR', 'DEFAULT') would not return the correct default value.
@jcppman
Copy link
Author

jcppman commented Jan 29, 2025

spotted a potential fix. created a PR

Copy link

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

@github-actions github-actions bot added the Stale label Mar 20, 2025
Copy link

This issue has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still need help on this issue

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants