We use variables that include $ within the strings, which we don't want to be expanded. Escaping with \$ works fine when it occurs at the start of the string, but not anywhere else within the string.
Example:
REACT_APP_MYVAR=\$bar.baz <- works as expected, value is "$bar.baz"
REACT_APP_MYVAR=foo\$bar.baz <- I'd expect "foo$bar.baz" but I get "foo\.baz"
I also tried working around the problem, like so:
BAR=\$bar
REACT_APP_MYVAR=foo$BAR.baz
But it gave the same result of "foo\.baz"
This sounds really annoying. Sorry.
Do you want to look into what's causing this?
This does appear to be a bug in dotenv-expand. It only looks for an escaped $ at the start of the string.
Right, it looks like this is the problem: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L25
Yes. I think there a couple of ways to fix it:
$ (instead of when it doesn't start with \$). This would make it impossible to expand variables inside a string which is maybe okay.$ in the string is escaped and only expand it if it's notCheck if each occurrence of $ in the string is escaped and only expand it if it's not
This makes sense to me. We should also document that behavior.
Fixed in [email protected].