fix: trim whitespaces when retrieving source refresh paths (#26400)

Signed-off-by: nitishfy <justnitish06@gmail.com>
This commit is contained in:
Nitish Kumar
2026-02-12 19:04:34 +05:30
committed by GitHub
parent 40412aaba3
commit 18efd0cf1b
2 changed files with 42 additions and 0 deletions

View File

@@ -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

View File

@@ -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 {