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

set_key does not check if there is a carriage return before inserting new key #360

Closed
sperretcraft opened this issue Oct 13, 2021 · 2 comments · Fixed by #361
Closed

set_key does not check if there is a carriage return before inserting new key #360

sperretcraft opened this issue Oct 13, 2021 · 2 comments · Fixed by #361

Comments

@sperretcraft
Copy link

Example script :

import os
import dotenv

DOTENV_FILE = os.path.join(os.path.dirname(__file__), ".env")

def init_dotenv():
    with open(DOTENV_FILE, "w") as fp:
        fp.write("TEST=ABCD") 


def print_dotenv():
    with open(DOTENV_FILE) as fp:
        content = fp.read()
    print("-" * 30, "DOTENV", "-" * 30)
    print(content)
    print()

init_dotenv()
print_dotenv()
dotenv.set_key(DOTENV_FILE, "FOO", "1234")
print_dotenv()

Output

------------------------------ DOTENV ------------------------------
TEST=ABCD

------------------------------ DOTENV ------------------------------
TEST=ABCDFOO='1234'


Is this something you want to fix ?

@saeedghx68
Copy link

I don't think it can a bug, you can change your code same as the library to put '\n'

@bbc2
Copy link
Collaborator

bbc2 commented Oct 23, 2021

This is indeed a bug. I made a fix in #361. I hope that it will solve your issue.

@bbc2 bbc2 closed this as completed in #361 Nov 11, 2021
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.

3 participants