segmentio / chamber

CLI for managing secrets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect escape of exclamation mark in export

mwisnicki opened this issue · comments

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.

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.

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

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

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

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

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.