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

Multiline string support #156

Merged
merged 12 commits into from Jan 27, 2023
Merged

Multiline string support #156

merged 12 commits into from Jan 27, 2023

Conversation

joho
Copy link
Owner

@joho joho commented Sep 24, 2021

Supersedes #118 (same PR, but rebased off master and with some extra test coverage) and fixes #117

@@ -28,6 +28,16 @@ import (

const doubleQuoteSpecialChars = "\\\n\r\"!$`"

// Parse reads an env file from io.Reader, returning a map of keys and values.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is out of sync with the code.

@coolaj86
Copy link
Contributor

coolaj86 commented Sep 24, 2021

Still failing on Windows. From the CI tests:

--- FAIL: TestLoadQuotedEnv (0.00s)
7
    godotenv_test.go:38: Mismatch for key 'OPTION_K': expected '"line one\nthis is \\'quoted\\'\none more line"' got '"line one\r\nthis is \\'quoted\\'\r\none more line"'
8
    godotenv_test.go:38: Mismatch for key 'OPTION_L': expected '"line 1\nline 2"' got '"line 1\r\nline 2"'
9
    godotenv_test.go:38: Mismatch for key 'OPTION_M': expected '"line one\nthis is \"quoted\"\none more line"' got '"line one\r\nthis is \"quoted\"\r\none more line"'
10
    godotenv_test.go:38: Mismatch for key 'OPTION_J': expected '"line 1\nline 2"' got '"line 1\r\nline 2"'

It looks like we want to convert Windows newlines into Unix newlines.

Perhaps the winning strategy will be to Replace \r\n with \n (then replace \r with \n just to be safe) and then parse without any special conditions for \r thereafter.

Thoughts?

parser.go Show resolved Hide resolved
@austinsasko
Copy link
Contributor

@joho please see the suggestion I made, that will fix this issue and get this project multiline support

Copy link

@luisdavim luisdavim left a comment

Choose a reason for hiding this comment

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

LGTM

@johnstonmatt
Copy link

thanks for contributing this work!

would it be possible for me to help with merging?

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 this pull request may close these issues.

Library can't parse multiline values properly
6 participants