Skip to content

Commit d2a9f42

Browse files
committed
fix: label values when dot are present
Label values can't start nor finish with a `.` (dot). This contribution ensures that any dot at the beginning or end of a label value is removed. Signed-off-by: Francesco Ilario <filario@redhat.com>
1 parent 861a507 commit d2a9f42

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

pkg/formatting/k8labels.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func CleanValueKubernetes(s string) string {
1818
}
1919

2020
replasoeur := strings.NewReplacer(":", "-", "/", "-", " ", "_", "[", "__", "]", "__")
21-
s = strings.TrimRight(s, " -_[]")
22-
s = strings.TrimLeft(s, " -_[]")
21+
s = strings.TrimRight(s, " .-_[]")
22+
s = strings.TrimLeft(s, " .-_[]")
2323
replaced := replasoeur.Replace(s)
2424
return strings.TrimSpace(replaced)
2525
}

pkg/formatting/k8labels_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ func TestK8LabelsCleanup(t *testing.T) {
5757
str: "secret:name/with_underscores",
5858
want: "secret-name-with_underscores",
5959
},
60+
{
61+
name: "starts with a .",
62+
str: ".i-start-with-a-dot",
63+
want: "i-start-with-a-dot",
64+
},
65+
{
66+
name: "ends with a .",
67+
str: "i-end-with-a-dot.",
68+
want: "i-end-with-a-dot",
69+
},
70+
{
71+
name: "long value once cut starts with a .",
72+
str: "everythingbeforethedotisdropped.thesehereare61chars-62withdot-previouscharacterswillbedropped",
73+
want: "thesehereare61chars-62withdot-previouscharacterswillbedropped",
74+
},
6075
}
6176

6277
for _, tt := range tests {

0 commit comments

Comments
 (0)