Skip to content

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

Closed

Description

@jdcrensh

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"

Activity

  1. gaearon commented on Feb 2, 2018

    @gaearon
    Contributor

    This sounds really annoying. Sorry.

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

  2. iansu commented on Feb 2, 2018

    @iansu
    Contributor

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

  3. jdcrensh commented on Feb 2, 2018

    @jdcrensh
    ContributorAuthor
  4. iansu commented on Feb 2, 2018

    @iansu
    Contributor

    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
  5. gaearon commented on Feb 2, 2018

    @gaearon
    Contributor

    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.

  6. gaearon commented on Feb 9, 2018

    @gaearon
    Contributor

    Fixed in react-scripts@1.1.1.

  7. locked and limited conversation to collaborators on Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions