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

dotenv-expand breaking build when "$" is used #3961

Closed
jdcrensh opened this issue Feb 2, 2018 · 6 comments
Closed

dotenv-expand breaking build when "$" is used #3961

jdcrensh opened this issue Feb 2, 2018 · 6 comments

Comments

@jdcrensh
Copy link
Contributor

jdcrensh commented Feb 2, 2018

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"

@gaearon
Copy link
Contributor

gaearon commented Feb 2, 2018

This sounds really annoying. Sorry.

Do you want to look into what's causing this?

@iansu
Copy link
Contributor

iansu commented Feb 2, 2018

This does appear to be a bug in dotenv-expand. It only looks for an escaped $ at the start of the string.

@jdcrensh
Copy link
Contributor Author

jdcrensh commented Feb 2, 2018

Right, it looks like this is the problem: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L25

@iansu
Copy link
Contributor

iansu commented Feb 2, 2018

Yes. I think there a couple of ways to fix it:

  1. Only expand when the variable starts with $ (instead of when it doesn't start with \$). This would make it impossible to expand variables inside a string which is maybe okay.
  2. Check if each occurrence of $ in the string is escaped and only expand it if it's not

@gaearon
Copy link
Contributor

gaearon commented Feb 2, 2018

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

@gaearon
Copy link
Contributor

gaearon commented Feb 9, 2018

Fixed in react-scripts@1.1.1.

1msoft added a commit to 1msoft/create-react-app that referenced this issue Feb 10, 2018
akstuhl pushed a commit to akstuhl/create-react-app that referenced this issue Mar 15, 2018
zmitry pushed a commit to zmitry/create-react-app that referenced this issue Sep 30, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants