summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2021-04-20 19:11:21 -0700
committerGitHub <[email protected]>2021-04-20 19:11:21 -0700
commit679be43af38a865f8318ed9bc3fde7ae424a2dad (patch)
tree5a1dae1764072858946018577df22b1ad622db4a /parse.go
parent9d937ba6c92804fb0880d4f7ce1fd0cbfd239afe (diff)
parent2e81334206442a1853cdc5a3f626e8ee0b113494 (diff)
Merge pull request #153 from alexflint/test-empty-mapv1.4.1
Fix case where an empty environment variable is parsed in a slice or map
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/parse.go b/parse.go
index 94c0a89..13e8195 100644
--- a/parse.go
+++ b/parse.go
@@ -441,13 +441,17 @@ func (p *Parser) captureEnvVars(specs []*spec, wasPresent map[*spec]bool) error
if spec.cardinality == multiple {
// expect a CSV string in an environment
// variable in the case of multiple values
- values, err := csv.NewReader(strings.NewReader(value)).Read()
- if err != nil {
- return fmt.Errorf(
- "error reading a CSV string from environment variable %s with multiple values: %v",
- spec.env,
- err,
- )
+ var values []string
+ var err error
+ if len(strings.TrimSpace(value)) > 0 {
+ values, err = csv.NewReader(strings.NewReader(value)).Read()
+ if err != nil {
+ return fmt.Errorf(
+ "error reading a CSV string from environment variable %s with multiple values: %v",
+ spec.env,
+ err,
+ )
+ }
}
if err = setSliceOrMap(p.val(spec.dest), values, !spec.separate); err != nil {
return fmt.Errorf(