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

Incorrect escape of exclamation mark in export #485

Closed
mwisnicki opened this issue May 7, 2024 · 6 comments · Fixed by #521
Closed

Incorrect escape of exclamation mark in export #485

mwisnicki opened this issue May 7, 2024 · 6 comments · Fixed by #521

Comments

@mwisnicki
Copy link

I have an exclamation mark in the middle of value: "a!b"

Export with chamber env foo works fine but chamber export --format dotenv foo incorrectly escapes the excalamation to "a\!b". The same thing happens with tfvars format.

@bhavanki
Copy link
Contributor

For the dotenv format: The escaping of the exclamation point derives from https://github.com/joho/godotenv, which explicitly includes it among characters needing escaping. There is a godotenv issue about this, but the (former) repo maintainer claims that the escaping is correct to maintain compatibility with the Ruby and node dotenv libraries. So, escaping is probably the right thing to do.

We could add an option to avoid escaping exclamation points, but then the resulting file wouldn't be in correct dotenv format. (It would make it directly consumable by the shell, though ... probably.) Another choice is to make a new output format like shell which doesn't do the escaping.

@mwisnicki
Copy link
Author

It seems like that maintainer is asking rather than claiming that is the behavior ruby/node. Someone will need to check it.

@mwisnicki
Copy link
Author

Tested with ruby and it works as expected:

echo 'FOO="1!2"' > .env 
gem install dotenv
ruby -r 'dotenv/load' -e 'puts ENV["FOO"]'

Returns 1!2

@mwisnicki
Copy link
Author

Same thing with node:

npm install dotenv
node -e 'require("dotenv").config(); console.log(process.env.FOO)'

Outputs: 1!2

No need for incorrect escape of !.

@mwisnicki
Copy link
Author

mwisnicki commented May 29, 2024

And it is generally assumed .env files have format that can be sourced from shell.

A lot of scripts rely on that:
https://github.com/search?q=%22source+.env%22+language%3AShell&type=code&l=Shell

@bhavanki
Copy link
Contributor

Thank you for all that legwork! 🙏 I'm convinced.

If you'd like to submit a PR yourself to fix chamber, please do. I recently made sure that our contributing guidelines were still valid.

bhavanki added a commit that referenced this issue Jun 17, 2024
Despite the github.com/joho/godotenv implementation which originated
dotenv support here, neither github.com/bkeepers/dotenv (Ruby) nor
github.com/motdotla/dotenv (Node) escape exclamation points in the
format. See #485 for
research.

Fixes #485
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 a pull request may close this issue.

2 participants