Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 6f30f0c

Browse files
committed
support for equals in yaml-style lines
1 parent 84bf91f commit 6f30f0c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

godotenv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ func parseLine(line string) (key string, value string, err error) {
198198
line = strings.Join(segmentsToKeep, "#")
199199
}
200200

201-
// now split key from value
201+
firstEquals := strings.Index(line, "=")
202+
firstColon := strings.Index(line, ":")
202203
splitString := strings.SplitN(line, "=", 2)
203-
204-
if len(splitString) != 2 {
205-
// try yaml mode!
204+
if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) {
205+
//this is a yaml-style line
206206
splitString = strings.SplitN(line, ":", 2)
207207
}
208208

godotenv_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ func TestParsing(t *testing.T) {
205205
// parses yaml style options
206206
parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1")
207207

208+
//parses yaml values with equal signs
209+
parseAndCompare(t, "OPTION_A: Foo=bar", "OPTION_A", "Foo=bar")
210+
211+
// parses non-yaml options with colons
212+
parseAndCompare(t, "OPTION_A=1:B", "OPTION_A", "1:B")
213+
208214
// parses export keyword
209215
parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2")
210216
parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\n")

0 commit comments

Comments
 (0)