mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
fix: trim whitespaces when retrieving source refresh paths (#26400)
Signed-off-by: nitishfy <justnitish06@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user