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

fix: Correctly parse newline and multiline strings in dotenv files #192

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

FranzGB
Copy link
Contributor

@FranzGB FranzGB commented Jun 11, 2024

Proposed Changes

  • test: Introduced tests to validate correct handling of newline characters \n and multiline strings in dotenv files.
  • fix: Implemented parsing of newline and multiline strings in dotenv files accurately

This pull request addresses issue #186. I wasn't sure if we should parse it as a newline or as a literal string. I decided to go with the latter. But happy to change it if needed. Let me know if you have any feedback.

Additionally, I noticed that our current tests depend heavily on the index of parsed (key, value) pairs, which could make them fragile and prone to breaking with minor changes in the fixture. I propose that we refactor these tests to make them more robust and resilient to changes. I look forward to hearing your thoughts on this.

@FranzGB FranzGB self-assigned this Jun 11, 2024
@FranzGB FranzGB linked an issue Jun 11, 2024 that may be closed by this pull request
where
newlineChar = string "\\n" >> return '\n'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FranzGB I see normalChar parses any char that doesn't need escape. Do you know why that doesn't include the \n?

Copy link
Contributor Author

@FranzGB FranzGB Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Cris! Yes, basically this line escapedChar = (char '\\' *> anySingle) <?> "escaped character" is eating all the \ not treating \n as a single character and leaving just the n as that is a candiate for normalChar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have another idea on how could we achieve this without adding a new function here (newlineChar <|> escapedChar <|> normalChar) but it will have to require modifying escapedChar function. Maybe we can catch up on this WDYT?

Copy link
Collaborator

@CristhianMotoche CristhianMotoche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FranzGB LGTM! Although, I would like to understand a little bit more why this wasn't parsing the \n before.

@FranzGB FranzGB force-pushed the bug-escape-new-line-characters branch from 0f52234 to 5dff2e9 Compare August 13, 2024 07:31
Copy link
Collaborator

@CristhianMotoche CristhianMotoche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CristhianMotoche CristhianMotoche merged commit 8add769 into main Aug 19, 2024
7 checks passed
@CristhianMotoche CristhianMotoche deleted the bug-escape-new-line-characters branch August 19, 2024 15:42
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 this pull request may close these issues.

parseFile doesn't seem to escape characters as expected
2 participants