Codebase list golang-github-joho-godotenv / 823f94b
Merge pull request #70 from hairyhenderson/support-keys-beginning-with-export-66 Support key names beginning with 'export' John Barton authored 5 years ago GitHub committed 5 years ago
2 changed file(s) with 10 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
251251 }
252252
253253 // Parse the key
254 key = splitString[0]
255 if strings.HasPrefix(key, "export") {
256 key = strings.TrimPrefix(key, "export")
257 }
258 key = strings.Trim(key, " ")
254 re := regexp.MustCompile(`^\s*(?:export\s+)?(.*?)\s*$`)
255 key = re.ReplaceAllString(splitString[0], "$1")
259256
260257 // Parse the value
261258 value = parseValue(splitString[1], envMap)
44 "fmt"
55 "os"
66 "reflect"
7 "strings"
78 "testing"
8 "strings"
99 )
1010
1111 var noopPresets = make(map[string]string)
312312 // parses export keyword
313313 parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2")
314314 parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\\n")
315 parseAndCompare(t, "export exportFoo=2", "exportFoo", "2")
316 parseAndCompare(t, "exportFOO=2", "exportFOO", "2")
317 parseAndCompare(t, "export_FOO =2", "export_FOO", "2")
318 parseAndCompare(t, "export.FOO= 2", "export.FOO", "2")
319 parseAndCompare(t, "export\tOPTION_A=2", "OPTION_A", "2")
320 parseAndCompare(t, " export OPTION_A=2", "OPTION_A", "2")
321 parseAndCompare(t, "\texport OPTION_A=2", "OPTION_A", "2")
315322
316323 // it 'expands newlines in quoted strings' do
317324 // expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz")