joho / godotenv

A Go port of Ruby's dotenv library (Loads environment variables from .env files)
http://godoc.org/github.com/joho/godotenv
MIT License
8.49k stars 405 forks source link

`-` is not supported in the key from version 1.5 but is supported in 1.4. Can we please take a look here ? This is a very basic use case. #209

Closed raghavharness closed 1 year ago

raghavharness commented 1 year ago

.env file content: go-version=hello

Error while reading this file: unexpected character "-" in variable name near "go-version=hello\n"

The same works with 1.4 version. @joho Request you to take a look into this.

joho commented 1 year ago

Thanks for raising.

While this could count as a regression against past versions, I'm counting this as undefined behaviour, and won't be fixing it.

I've gone and tested against the upstream ruby library and that format isn't supported there.

image

It even syntax highlights funny in vim which is a reasonable leading indicator that usage is NQR.

bradrydzewski commented 1 year ago

@joho I wanted to provide some additional context. Although bash does not support dashes in environment variables, they are supported by some operating system syscalls [1], and they are valid on windows. GitHub Actions supports environment files [2] and they allow dashes as well, and we are using this library to parse the GitHub Actions env files. For better or worse, many GitHub Actions output variables with dashes.

We completely understand they may be out of scope for this library, especially if you are tracking compatibility with the ruby version. We are going to keep an internal fork to patch the behavior, but if you ever change your mind, we would be happy to contribute back.

[1] https://go.dev/play/p/YWrwwVVLhAK [2] https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files