diff --git a/oauth.go b/oauth.go index 13a847f..be2cf58 100755 --- a/oauth.go +++ b/oauth.go @@ -188,8 +188,8 @@ func getBaseUrlString(u *url.URL) string { host = hostPort[0] } path := u.EscapedPath() - if path == "" { - path = "/" + if path == "" || path[0] != '/' { + path = "/" + path } return fmt.Sprintf("%v://%v%v", scheme, host, path) } diff --git a/oauth_test.go b/oauth_test.go index cce1098..f60d00e 100755 --- a/oauth_test.go +++ b/oauth_test.go @@ -253,6 +253,15 @@ func TestGetBaseUrlString_ShouldAddTrailingSlash(t *testing.T) { } } +func TestGetBaseUrlString_ShouldAddLeadingSlashToPath(t *testing.T) { + u, _ := url.Parse("https://api.mastercard.com") + u.Path = "test/service" + baseUrl := getBaseUrlString(u) + if "https://api.mastercard.com/test/service" != baseUrl { + t.Errorf("Something went wrong, got %v", baseUrl) + } +} + func TestGetBaseUrlString_ShouldUseLowercaseSchemesAndHosts(t *testing.T) { u, _ := url.Parse("HTTPS://API.MASTERCARD.COM/TEST") baseUrl := getBaseUrlString(u)