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

parseFile doesn't seem to escape characters as expected #186

Open
Martinsos opened this issue Nov 28, 2023 · 3 comments · May be fixed by #192
Open

parseFile doesn't seem to escape characters as expected #186

Martinsos opened this issue Nov 28, 2023 · 3 comments · May be fixed by #192
Labels
Milestone

Comments

@Martinsos
Copy link

Martinsos commented Nov 28, 2023

Here is an .env file I used to illustrate the potential issue:

TEST1="a\nb"
TEST2='a\nb'
TEST3=a\nb
TEST4="a\\nb"

Now, when I run parseFile "testenv" in ghci, I get the following output:
image

Formatted:

[ ("TEST1","anb"),
  ("TEST2","anb"),
  ("TEST3","anb"),
  ("TEST4","a\\nb"),
]

This is not the output I would expect though.

Output I would expect is the following:

[ ("TEST1","a\nb"),
  ("TEST2","a\nb"),
  ("TEST3","a\nb"),
  ("TEST4","a\\nb")  -- OK I am not 100% sure what to expect here, this might be ok.
]

Is my expectation wrong here, or is this potentially a bug in the Dotenv?

I am using dotenv ^>= 0.10.0.

Thanks!

@CristhianMotoche
Copy link
Collaborator

Hi @Martinsos Thanks for reporting that. I think what you mention makes sense but I need to take a look at the parser to clarify if this is expected and what would be the correct way to handle breaking lines.

@CristhianMotoche CristhianMotoche added the needs review Review the relevance of the issue/pull request label Dec 11, 2023
@Martinsos
Copy link
Author

Thanks @CristhianMotoche !

I don't care much about the "\n" case, but "\n" being parsed as "n" is quite tricky, it makes it impossible to enter a string with a newline inside the env (and for example, Google gives you PEM key as a secret and it has newlines!). The only solution we found so far was to encode it with base64, putting it in .env like that, and then decoding it after being red for dotenv.

Let me know if I can help in some way!

@CristhianMotoche CristhianMotoche added bug and removed needs review Review the relevance of the issue/pull request labels Jan 22, 2024
@CristhianMotoche
Copy link
Collaborator

Hey @Martinsos I was able to reproduce the issue. Indeed, it seems something wrong in the parser. FWIW, I think you can add new lines instead of the \n character to represent new lines. For example:

Given this .env:

BAR="a
b"

parseFile will return:

ghci> parseFile ".env"
[("BAR","a\nb")]

I hope that works as a workaround until we find a solution for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants