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

Commit 9be76b3

Browse files
author
Takumasa Sakao
committed
Pass envMap to parseLine & parseValue
1 parent 6d367c1 commit 9be76b3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

godotenv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func Parse(r io.Reader) (envMap map[string]string, err error) {
112112
for _, fullLine := range lines {
113113
if !isIgnoredLine(fullLine) {
114114
var key, value string
115-
key, value, err = parseLine(fullLine)
115+
key, value, err = parseLine(fullLine, envMap)
116116

117117
if err != nil {
118118
return
@@ -209,7 +209,7 @@ func readFile(filename string) (envMap map[string]string, err error) {
209209
return Parse(file)
210210
}
211211

212-
func parseLine(line string) (key string, value string, err error) {
212+
func parseLine(line string, envMap map[string]string) (key string, value string, err error) {
213213
if len(line) == 0 {
214214
err = errors.New("zero length string")
215215
return
@@ -259,11 +259,11 @@ func parseLine(line string) (key string, value string, err error) {
259259
key = strings.Trim(key, " ")
260260

261261
// Parse the value
262-
value = parseValue(splitString[1])
262+
value = parseValue(splitString[1], envMap)
263263
return
264264
}
265265

266-
func parseValue(value string) string {
266+
func parseValue(value string, envMap map[string]string) string {
267267

268268
// trim
269269
value = strings.Trim(value, " ")

godotenv_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
var noopPresets = make(map[string]string)
1212

1313
func parseAndCompare(t *testing.T, rawEnvLine string, expectedKey string, expectedValue string) {
14-
key, value, _ := parseLine(rawEnvLine)
14+
key, value, _ := parseLine(rawEnvLine, noopPresets)
1515
if key != expectedKey || value != expectedValue {
1616
t.Errorf("Expected '%v' to parse as '%v' => '%v', got '%v' => '%v' instead", rawEnvLine, expectedKey, expectedValue, key, value)
1717
}
@@ -280,7 +280,7 @@ func TestParsing(t *testing.T) {
280280
// it 'throws an error if line format is incorrect' do
281281
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
282282
badlyFormattedLine := "lol$wut"
283-
_, _, err := parseLine(badlyFormattedLine)
283+
_, _, err := parseLine(badlyFormattedLine, noopPresets)
284284
if err == nil {
285285
t.Errorf("Expected \"%v\" to return error, but it didn't", badlyFormattedLine)
286286
}

0 commit comments

Comments
 (0)