Skip to content

Commit 851ac33

Browse files
authored
Use strings.TrimSuffix instead of strings.Trim (#6)
strings.Trim removes the unicode points in the input cutset instead of trimming the entire matched string.
1 parent 8049ab3 commit 851ac33

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/httpapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func parseURL(s string) (string, error) {
184184
if err != nil {
185185
return "", fmt.Errorf("failed to parse %#v: %w", s, err)
186186
}
187-
return strings.TrimLeft(strings.Trim(parsed.Path, ".git"), "/"), nil
187+
return strings.TrimLeft(strings.TrimSuffix(parsed.Path, ".git"), "/"), nil
188188
}
189189

190190
func secretRefFromQuery(v url.Values) (types.NamespacedName, bool) {

pkg/httpapi/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ func TestParseURL(t *testing.T) {
267267
wantRepo string
268268
wantErr string
269269
}{
270-
{"https://github.com/example/gitops.git", "example/gitops", ""},
270+
{"https://github.com/example/gitops.git?ref=main", "example/gitops", ""},
271271
{"%%foo.html", "", "invalid URL escape"},
272+
{"https://github.com/example/testing.git", "example/testing", ""},
272273
}
273274

274275
for _, tt := range urlTests {

0 commit comments

Comments
 (0)