Skip to content

Commit 141af9f

Browse files
committed
support legacy boolean but warn user about incompatibility
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 298fa92 commit 141af9f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

interpolation/interpolation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func recursiveInterpolate(value interface{}, path Path, opts Options) (interface
7272
switch value := value.(type) {
7373
case string:
7474
newValue, err := opts.Substitute(value, template.Mapping(opts.LookupValue))
75-
if err != nil || newValue == value {
75+
if err != nil {
7676
return value, newPathError(path, err)
7777
}
7878
caster, ok := opts.getCasterForPath(path)

loader/interpolate.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
interp "github.com/compose-spec/compose-go/interpolation"
2424
"github.com/pkg/errors"
25+
"github.com/sirupsen/logrus"
2526
)
2627

2728
var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
@@ -114,9 +115,15 @@ func toFloat32(value string) (interface{}, error) {
114115
// should match http://yaml.org/type/bool.html
115116
func toBoolean(value string) (interface{}, error) {
116117
switch strings.ToLower(value) {
117-
case "y", "yes", "true", "on":
118+
case "true":
118119
return true, nil
119-
case "n", "no", "false", "off":
120+
case "false":
121+
return false, nil
122+
case "y", "yes", "on":
123+
logrus.Warnf("%q for boolean is not supported by YAML 1.2, please use `true`", value)
124+
return true, nil
125+
case "n", "no", "off":
126+
logrus.Warnf("%q for boolean is not supported by YAML 1.2, please use `false`", value)
120127
return false, nil
121128
default:
122129
return nil, errors.Errorf("invalid boolean: %s", value)

loader/loader_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,17 @@ services:
21262126
assert.ErrorContains(t, err, "services.test.build.ssh must be a mapping")
21272127
}
21282128

2129+
func TestLoadLegacyBoolean(t *testing.T) {
2130+
actual, err := loadYAML(`
2131+
name: load-legacy-boolean
2132+
services:
2133+
test:
2134+
init: yes # used to be a valid YAML bool, removed in YAML 1.2
2135+
`)
2136+
assert.NilError(t, err)
2137+
assert.Check(t, *actual.Services[0].Init)
2138+
}
2139+
21292140
func TestLoadSSHWithDefaultValueInBuildConfig(t *testing.T) {
21302141
actual, err := loadYAML(`
21312142
name: load-ssh-with-default-value-in-build-config

0 commit comments

Comments
 (0)