fix: apply expanduser to dotenv_path - #615
Conversation
Apply os.path.expanduser() / Path.expanduser() to dotenv_path so that ~ is properly expanded to the user's home directory. The fix preserves the original type (str stays str, Path stays Path) and is applied in DotEnv.__init__, set_key, and unset_key.
|
Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed. |
The library fix covered set and unset, which go through set_key and unset_key, but list, get and run open --file directly, so `dotenv --file=~/.env list` still failed. Expand it once in the cli group. Test every library entry point with str and Path inputs, and every CLI subcommand. Add a CHANGELOG entry.
|
Thanks @veeceey, and sorry for the wait. Your change is correct: I reproduced #525 independently and arrived at the same fix in the same three places. I pushed two commits on top of yours; your commit is unchanged:
Why the CLI change. With only the library fix, the
Tests. 13 library cases cover every entry point with
Locally: 286 passed,
|
Summary
os.path.expanduser()(forstrpaths) andPath.expanduser()(forPathobjects) todotenv_pathso that~is properly expanded to the user's home directorystrinputs remainstr,Pathinputs remainPathDotEnv.__init__,set_key(), andunset_key()— all places wheredotenv_pathis used directlyFixes #525
Test plan
test_main.pypass with no modificationsdotenv_path="~/.env"correctly expands to the full home directory pathPath("~/.env")correctly expands viaPath.expanduser()~are unchangedNoneis handled correctly (no expansion attempted)