Skip to content

Commit 42d602d

Browse files
authored
Merge pull request #189 from arran4/codex/add-edge-case-tests-and-fix-issues
Fix JoinURL trailing slash handling and add edge-case tests
2 parents a90aa07 + 6255538 commit 42d602d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

urlutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "strings"
66
// Additional leading or trailing slashes are removed from elem.
77
func JoinURL(base, elem string) string {
88
base = strings.TrimRight(base, "/")
9-
elem = strings.TrimLeft(elem, "/")
9+
elem = strings.Trim(elem, "/")
1010
if base == "" {
1111
return "/" + elem
1212
}

urlutils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ func TestJoinURL(t *testing.T) {
1212
{"http://example.com/", "oauth2Callback", "http://example.com/oauth2Callback"},
1313
{"http://example.com///", "oauth2Callback", "http://example.com/oauth2Callback"},
1414
{"http://example.com/base", "oauth2Callback", "http://example.com/base/oauth2Callback"},
15+
{"http://example.com/base/", "/oauth2Callback///", "http://example.com/base/oauth2Callback"},
16+
{"", "///oauth2Callback///", "/oauth2Callback"},
1517
}
1618
for _, tt := range tests {
1719
got := JoinURL(tt.base, tt.elem)

0 commit comments

Comments
 (0)