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

Commit 263a1dd

Browse files
Support key names beginning with 'export'
Signed-off-by: Dave Henderson <[email protected]>
1 parent 69ed1d9 commit 263a1dd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

godotenv.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,8 @@ func parseLine(line string, envMap map[string]string) (key string, value string,
252252
}
253253

254254
// Parse the key
255-
key = splitString[0]
256-
if strings.HasPrefix(key, "export") {
257-
key = strings.TrimPrefix(key, "export")
258-
}
259-
key = strings.Trim(key, " ")
255+
re := regexp.MustCompile(`^\s*(?:export\s+)?(.*?)\s*$`)
256+
key = re.ReplaceAllString(splitString[0], "$1")
260257

261258
// Parse the value
262259
value = parseValue(splitString[1], envMap)

godotenv_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"os"
77
"reflect"
8-
"testing"
98
"strings"
9+
"testing"
1010
)
1111

1212
var noopPresets = make(map[string]string)
@@ -313,6 +313,13 @@ func TestParsing(t *testing.T) {
313313
// parses export keyword
314314
parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2")
315315
parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\\n")
316+
parseAndCompare(t, "export exportFoo=2", "exportFoo", "2")
317+
parseAndCompare(t, "exportFOO=2", "exportFOO", "2")
318+
parseAndCompare(t, "export_FOO =2", "export_FOO", "2")
319+
parseAndCompare(t, "export.FOO= 2", "export.FOO", "2")
320+
parseAndCompare(t, "export\tOPTION_A=2", "OPTION_A", "2")
321+
parseAndCompare(t, " export OPTION_A=2", "OPTION_A", "2")
322+
parseAndCompare(t, "\texport OPTION_A=2", "OPTION_A", "2")
316323

317324
// it 'expands newlines in quoted strings' do
318325
// expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")

0 commit comments

Comments
 (0)