Merge pull request #70 from hairyhenderson/support-keys-beginning-with-export-66

Support key names beginning with 'export'
pull/69/head^2
John Barton 2019-02-04 15:26:24 +11:00 committed by GitHub
commit 823f94bb9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -252,11 +252,8 @@ func parseLine(line string, envMap map[string]string) (key string, value string,
}
// Parse the key
key = splitString[0]
if strings.HasPrefix(key, "export") {
key = strings.TrimPrefix(key, "export")
}
key = strings.Trim(key, " ")
re := regexp.MustCompile(`^\s*(?:export\s+)?(.*?)\s*$`)
key = re.ReplaceAllString(splitString[0], "$1")
// Parse the value
value = parseValue(splitString[1], envMap)

View File

@ -5,8 +5,8 @@ import (
"fmt"
"os"
"reflect"
"testing"
"strings"
"testing"
)
var noopPresets = make(map[string]string)
@ -313,6 +313,13 @@ func TestParsing(t *testing.T) {
// parses export keyword
parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2")
parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\\n")
parseAndCompare(t, "export exportFoo=2", "exportFoo", "2")
parseAndCompare(t, "exportFOO=2", "exportFOO", "2")
parseAndCompare(t, "export_FOO =2", "export_FOO", "2")
parseAndCompare(t, "export.FOO= 2", "export.FOO", "2")
parseAndCompare(t, "export\tOPTION_A=2", "OPTION_A", "2")
parseAndCompare(t, " export OPTION_A=2", "OPTION_A", "2")
parseAndCompare(t, "\texport OPTION_A=2", "OPTION_A", "2")
// it 'expands newlines in quoted strings' do
// expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")