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

fix(env): compatible with env variables ended with unescaped $ #12031

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

sun0day
Copy link
Member

@sun0day sun0day commented Feb 12, 2023

Description

fix #12006

.env:

VITE_EXPAND_A=$EXPAND
VITE_EXPAND_B=$DEPEND_ENV
VITE_ESCAPE_A=escape\$
VITE_ESCAPE_B=escape$
IRRELEVANT_ENV=$DEPEND_ENV
IRRELEVANT_ESCAPE_ENV=irrelevant$
DEPEND_ENV=depend

after parsing .env, you will get

env = {
  VITE_EXPAND_A: 'expand',
  VITE_EXPAND_B: 'depend',
  VITE_ESCAPE_A: 'escape$',
  VITE_ESCAPE_B: 'escape$'
}

Irrelevant env variables and VITE_ env variables won't impact each other.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy
Copy link
Member

bluwy commented Feb 16, 2023

IIUC this PR would allow trailing $ for any env var, which isn't exactly the same proposed changes from #12006 (comment), but thinking about it more, I think this is indeed the best solution forward without deviating too much from dotenv-expand.

Looks like there's a merge conflict, but the changes looks good to me.

@sun0day
Copy link
Member Author

sun0day commented Feb 16, 2023

IIUC this PR would allow trailing $ for any env var, which isn't exactly the same proposed changes from #12006 (comment), but thinking about it more, I think this is indeed the best solution forward without deviating too much from dotenv-expand.

Looks like there's a merge conflict, but the changes looks good to me.

Yeah. It's a bit of a compromise, but I think it's the best solution by far. And it makes sense to leave the trailing $ as it is.

@patak-dev patak-dev merged commit 05b3df0 into vitejs:main Feb 16, 2023
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

Successfully merging this pull request may close these issues.

Vite fatal error when a variable in .env ends with "$", even if it is not accessible by Vite.
3 participants