From 13df5ffe73ebde9d53fa1832a3625a55888e5f64 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 12 Jan 2024 13:59:44 +0100 Subject: [PATCH] neutralize path separator when used in service name Signed-off-by: Nicolas De Loof --- loader/loader_test.go | 19 +++++++++++++++++++ tree/path.go | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/loader/loader_test.go b/loader/loader_test.go index 4b9d6bc0..693b9733 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -2942,3 +2942,22 @@ services: "nofile": {Soft: 20000, Hard: 40000}, }) } + +func TestServiceNameWithDots(t *testing.T) { + yaml := ` +name: test-service-name-with-dots +services: + test.a.b.c: + image: foo + ports: + - "5432" +` + _, err := LoadWithContext(context.Background(), types.ConfigDetails{ + ConfigFiles: []types.ConfigFile{ + { + Content: []byte(yaml), + }, + }, + }) + assert.NilError(t, err) +} diff --git a/tree/path.go b/tree/path.go index b73038b1..f8a8d9a6 100644 --- a/tree/path.go +++ b/tree/path.go @@ -43,6 +43,7 @@ func (p Path) Next(part string) Path { if p == "" { return Path(part) } + part = strings.ReplaceAll(part, pathSeparator, "👻") return Path(string(p) + pathSeparator + part) } @@ -80,3 +81,7 @@ func (p Path) Parent() Path { } return "" } + +func (p Path) String() string { + return strings.ReplaceAll(string(p), "👻", pathSeparator) +}