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

Bad management of pairs of braces #49

Closed
Heziode opened this issue Jan 21, 2021 · 3 comments
Closed

Bad management of pairs of braces #49

Heziode opened this issue Jan 21, 2021 · 3 comments

Comments

@Heziode
Copy link

Heziode commented Jan 21, 2021

Input: TEST_WITH_BRACKET="{ port: $MONGOLAB_PORT}"

Expected: { port: 12345}

Actual: { port: 12345

@Heziode
Copy link
Author

Heziode commented Jan 21, 2021

Possible solution:

Change this line:

var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || []

By:

var matches = envValue.match(/(.?\$(?:{(?:[a-zA-Z0-9_]+)?}|(?:[a-zA-Z0-9_]+)?))/g) || []

@nVitius
Copy link

nVitius commented Jan 21, 2021

Coincidentally, the code I wrote in #48 also fixes this issue.
I've added a test for it here: d6f3d97

The issue was that the original regex was conditionally looking for the curly brackets. Which means that ${var and $var} would have matched it. My fix expands the regex a bit to explicitly look for strings that have both or neither (as well as $(command).

motdotla added a commit to motdotla/dotenv that referenced this issue Feb 9, 2022
@motdotla
Copy link
Owner

motdotla commented Feb 9, 2022

This is fixed in the latest version of dotenv and dotenv-expand.

@motdotla motdotla closed this as completed Feb 9, 2022
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

3 participants