motdotla / dotenv-expand

Variable expansion for dotenv. Expand variables already on your machine for use in your .env file.

Home Page:https://dotenvx.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad management of pairs of braces

Heziode opened this issue · comments

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

Expected: { port: 12345}

Actual: { port: 12345

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) || []

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).

commented

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