From 18efd0cf1beea5414f8e4811b055088dbb41c670 Mon Sep 17 00:00:00 2001 From: Nitish Kumar Date: Thu, 12 Feb 2026 19:04:34 +0530 Subject: [PATCH] fix: trim whitespaces when retrieving source refresh paths (#26400) Signed-off-by: nitishfy --- util/app/path/path.go | 5 +++++ util/app/path/path_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/util/app/path/path.go b/util/app/path/path.go index 88b409e36e..4ea95d7416 100644 --- a/util/app/path/path.go +++ b/util/app/path/path.go @@ -117,6 +117,11 @@ func GetSourceRefreshPaths(app *v1alpha1.Application, source v1alpha1.Applicatio var paths []string if hasAnnotation && annotationPaths != "" { for item := range strings.SplitSeq(annotationPaths, ";") { + // Trim whitespace because annotation values may contain spaces around + // separators (e.g. ".; /path"). Without trimming, paths like " /path" + // are not treated as absolute and empty/space-only entries may result + // in duplicate or incorrect refresh paths. + item = strings.TrimSpace(item) // skip empty paths if item == "" { continue diff --git a/util/app/path/path_test.go b/util/app/path/path_test.go index 07c043a586..06ce653ff8 100644 --- a/util/app/path/path_test.go +++ b/util/app/path/path_test.go @@ -192,6 +192,43 @@ func Test_GetAppRefreshPaths(t *testing.T) { source: v1alpha1.ApplicationSource{Path: "dry/path"}, expectedPaths: []string{"dry/path/deploy"}, }, + { + name: "annotation paths with spaces after semicolon", + app: getApp(ptr.To(".; dev/deploy; other/path"), ptr.To("source/path")), + source: v1alpha1.ApplicationSource{Path: "source/path"}, + expectedPaths: []string{ + "source/path", + "source/path/dev/deploy", + "source/path/other/path", + }, + }, + { + name: "annotation paths with spaces before semicolon", + app: getApp(ptr.To(". ;dev/deploy ;other/path"), ptr.To("source/path")), + source: v1alpha1.ApplicationSource{Path: "source/path"}, + expectedPaths: []string{ + "source/path", + "source/path/dev/deploy", + "source/path/other/path", + }, + }, + { + name: "annotation paths with spaces around absolute path", + app: getApp(ptr.To(" /fullpath/deploy ; other/path "), ptr.To("source/path")), + source: v1alpha1.ApplicationSource{Path: "source/path"}, + expectedPaths: []string{ + "fullpath/deploy", + "source/path/other/path", + }, + }, + { + name: "annotation paths only spaces and separators", + app: getApp(ptr.To(" ; ; . ; "), ptr.To("source/path")), + source: v1alpha1.ApplicationSource{Path: "source/path"}, + expectedPaths: []string{ + "source/path", + }, + }, } for _, tt := range tests {