forked from coop-cloud-mirrors/godotenv
Pass envMap to parseLine & parseValue
This commit is contained in:
parent
6d367c18ed
commit
9be76b3741
@ -112,7 +112,7 @@ func Parse(r io.Reader) (envMap map[string]string, err error) {
|
|||||||
for _, fullLine := range lines {
|
for _, fullLine := range lines {
|
||||||
if !isIgnoredLine(fullLine) {
|
if !isIgnoredLine(fullLine) {
|
||||||
var key, value string
|
var key, value string
|
||||||
key, value, err = parseLine(fullLine)
|
key, value, err = parseLine(fullLine, envMap)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -209,7 +209,7 @@ func readFile(filename string) (envMap map[string]string, err error) {
|
|||||||
return Parse(file)
|
return Parse(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLine(line string) (key string, value string, err error) {
|
func parseLine(line string, envMap map[string]string) (key string, value string, err error) {
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
err = errors.New("zero length string")
|
err = errors.New("zero length string")
|
||||||
return
|
return
|
||||||
@ -259,11 +259,11 @@ func parseLine(line string) (key string, value string, err error) {
|
|||||||
key = strings.Trim(key, " ")
|
key = strings.Trim(key, " ")
|
||||||
|
|
||||||
// Parse the value
|
// Parse the value
|
||||||
value = parseValue(splitString[1])
|
value = parseValue(splitString[1], envMap)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseValue(value string) string {
|
func parseValue(value string, envMap map[string]string) string {
|
||||||
|
|
||||||
// trim
|
// trim
|
||||||
value = strings.Trim(value, " ")
|
value = strings.Trim(value, " ")
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
var noopPresets = make(map[string]string)
|
var noopPresets = make(map[string]string)
|
||||||
|
|
||||||
func parseAndCompare(t *testing.T, rawEnvLine string, expectedKey string, expectedValue string) {
|
func parseAndCompare(t *testing.T, rawEnvLine string, expectedKey string, expectedValue string) {
|
||||||
key, value, _ := parseLine(rawEnvLine)
|
key, value, _ := parseLine(rawEnvLine, noopPresets)
|
||||||
if key != expectedKey || value != expectedValue {
|
if key != expectedKey || value != expectedValue {
|
||||||
t.Errorf("Expected '%v' to parse as '%v' => '%v', got '%v' => '%v' instead", rawEnvLine, expectedKey, expectedValue, key, value)
|
t.Errorf("Expected '%v' to parse as '%v' => '%v', got '%v' => '%v' instead", rawEnvLine, expectedKey, expectedValue, key, value)
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func TestParsing(t *testing.T) {
|
|||||||
// it 'throws an error if line format is incorrect' do
|
// it 'throws an error if line format is incorrect' do
|
||||||
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
||||||
badlyFormattedLine := "lol$wut"
|
badlyFormattedLine := "lol$wut"
|
||||||
_, _, err := parseLine(badlyFormattedLine)
|
_, _, err := parseLine(badlyFormattedLine, noopPresets)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected \"%v\" to return error, but it didn't", badlyFormattedLine)
|
t.Errorf("Expected \"%v\" to return error, but it didn't", badlyFormattedLine)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user