Skip to content

Commit 2955d4e

Browse files
ndeloofglours
authored andcommitted
report error using KEY=VALUE with whitespaces
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 5332032 commit 2955d4e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

loader/loader_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -3733,3 +3733,14 @@ services:
37333733
assert.Equal(t, policy, types.PullPolicyRefresh)
37343734
assert.Equal(t, duration, 2*24*time.Hour)
37353735
}
3736+
3737+
func TestEnvironmentWhitespace(t *testing.T) {
3738+
_, err := loadYAML(`
3739+
name: environment_whitespace
3740+
services:
3741+
test:
3742+
environment:
3743+
- DEBUG = true
3744+
`)
3745+
assert.Check(t, strings.Contains(err.Error(), "'services[test].environment': environment variable DEBUG is declared with a trailing space"))
3746+
}

types/mapping.go

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"sort"
2222
"strings"
23+
"unicode"
2324
)
2425

2526
// MappingWithEquals is a mapping type that can be converted from a list of
@@ -94,6 +95,9 @@ func (m *MappingWithEquals) DecodeMapstructure(value interface{}) error {
9495
mapping := make(MappingWithEquals, len(v))
9596
for _, s := range v {
9697
k, e, ok := strings.Cut(fmt.Sprint(s), "=")
98+
if unicode.IsSpace(rune(k[len(k)-1])) {
99+
return fmt.Errorf("environment variable %s is declared with a trailing space", k)
100+
}
97101
if !ok {
98102
mapping[k] = nil
99103
} else {

0 commit comments

Comments
 (0)