python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

set_key creates orphan .env file

Open TheGeeKing opened this issue 2 years ago • 0 comments

set_key states "If the .env path given doesn't exist, fails instead of risking creating an orphan .env somewhere in the filesystem".

set_key has no check if the file exists. As it uses rewrite which if path passed is not a file, it creates an empty file.

if not os.path.isfile(path):
        with open(path, mode="w", encoding=encoding) as source:
            source.write("")

https://github.com/theskumar/python-dotenv/blob/3ffcef60d10813b72ecf85d5941d51b0207cd40e/src/dotenv/main.py#L134

TheGeeKing avatar Aug 15 '23 16:08 TheGeeKing