diff options
| author | Alex Flint <[email protected]> | 2021-04-20 19:11:21 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-04-20 19:11:21 -0700 |
| commit | 679be43af38a865f8318ed9bc3fde7ae424a2dad (patch) | |
| tree | 5a1dae1764072858946018577df22b1ad622db4a /parse.go | |
| parent | 9d937ba6c92804fb0880d4f7ce1fd0cbfd239afe (diff) | |
| parent | 2e81334206442a1853cdc5a3f626e8ee0b113494 (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.go | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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( |
