Skip to content

Commit 3e768a8

Browse files
committed
Config: allow escaping dots in keys via '[unsplit.key]' syntax
1 parent 2f07cad commit 3e768a8

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Masterminds/sprig/v3 v3.3.0
88
github.com/blang/semver/v4 v4.0.0
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
10-
github.com/elastic/go-ucfg v0.8.8
10+
github.com/elastic/go-ucfg v0.8.9-0.20250307075119-2a22403faaea
1111
github.com/ghodss/yaml v1.0.0
1212
github.com/gkampitakis/go-snaps v0.5.8
1313
github.com/go-logr/logr v1.4.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZ
4242
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
4343
github.com/elastic/go-sysinfo v1.15.1 h1:zBmTnFEXxIQ3iwcQuk7MzaUotmKRp3OabbbWM8TdzIQ=
4444
github.com/elastic/go-sysinfo v1.15.1/go.mod h1:jPSuTgXG+dhhh0GKIyI2Cso+w5lPJ5PvVqKlL8LV/Hk=
45-
github.com/elastic/go-ucfg v0.8.8 h1:54KIF/2zFKfl0MzsSOCGOsZ3O2bnjFQJ0nDJcLhviyk=
46-
github.com/elastic/go-ucfg v0.8.8/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
45+
github.com/elastic/go-ucfg v0.8.9-0.20250307075119-2a22403faaea h1:SX+ZnuBacMQVu1sNniwUEpi9i3dBaYlbg1WDioQh/ho=
46+
github.com/elastic/go-ucfg v0.8.9-0.20250307075119-2a22403faaea/go.mod h1:4E8mPOLSUV9hQ7sgLEJ4bvt0KhMuDJa8joDT2QGAEKA=
4747
github.com/elastic/go-windows v1.0.2 h1:yoLLsAsV5cfg9FLhZ9EXZ2n2sQFKeDYrHenkcivY4vI=
4848
github.com/elastic/go-windows v1.0.2/go.mod h1:bGcDpBzXgYSqM0Gx3DM4+UxFj300SZLixie9u9ixLM8=
4949
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=

pkg/controller/common/settings/canonical_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
type CanonicalConfig ucfg.Config
2323

2424
// Options are config options for the YAML file. Currently contains only support for dotted keys.
25-
var Options = []ucfg.Option{ucfg.PathSep("."), ucfg.AppendValues}
25+
var Options = []ucfg.Option{ucfg.PathSep("."), ucfg.AppendValues, ucfg.EscapePath()}
2626

2727
// NewCanonicalConfig creates a new empty config.
2828
func NewCanonicalConfig() *CanonicalConfig {

pkg/controller/common/settings/canonical_config_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ import (
1313

1414
func TestCanonicalConfig_Render(t *testing.T) {
1515
config := MustCanonicalConfig(map[string]interface{}{
16-
"aaa": "aa a",
17-
"bbb": "b bb",
18-
"aab": "a a a",
19-
"key": map[string]interface{}{"emptyarray": []string{}},
20-
"withquotes": "aa\"bb\"aa",
21-
"zz": "zzz z z z",
16+
"[escaped.key]": map[string]interface{}{"[another.escaped.key]": "value"},
17+
"aaa": "aa a",
18+
"bbb": "b bb",
19+
"aab": "a a a",
20+
"key": map[string]interface{}{"emptyarray": []string{}},
21+
"withquotes": "aa\"bb\"aa",
22+
"zz": "zzz z z z",
2223
})
2324
output, err := config.Render()
2425
require.NoError(t, err)
25-
expected := []byte(`aaa: aa a
26+
expected := []byte(`'[escaped.key]':
27+
'[another.escaped.key]': value
28+
aaa: aa a
2629
aab: a a a
2730
bbb: b bb
2831
key:

0 commit comments

Comments
 (0)