Commit c3032f7b by Anthony Woods

Merge pull request #3890 from daniellee/joinurlfragments

No added trailing slash if proxypath is empty in JoinUrlFragments
parents f46eee96 74decb4b
......@@ -27,6 +27,11 @@ func (r *UrlQueryReader) Get(name string, def string) string {
func JoinUrlFragments(a, b string) string {
aslash := strings.HasSuffix(a, "/")
bslash := strings.HasPrefix(b, "/")
if len(b) == 0 {
return a
}
switch {
case aslash && bslash:
return a + b[1:]
......
package util
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestUrl(t *testing.T) {
Convey("When joining two urls where right hand side is empty", t, func() {
result := JoinUrlFragments("http://localhost:8080", "")
So(result, ShouldEqual, "http://localhost:8080")
})
Convey("When joining two urls where right hand side is empty and lefthand side has a trailing slash", t, func() {
result := JoinUrlFragments("http://localhost:8080/", "")
So(result, ShouldEqual, "http://localhost:8080/")
})
Convey("When joining two urls where neither has a trailing slash", t, func() {
result := JoinUrlFragments("http://localhost:8080", "api")
So(result, ShouldEqual, "http://localhost:8080/api")
})
Convey("When joining two urls where lefthand side has a trailing slash", t, func() {
result := JoinUrlFragments("http://localhost:8080/", "api")
So(result, ShouldEqual, "http://localhost:8080/api")
})
Convey("When joining two urls where righthand side has preceding slash", t, func() {
result := JoinUrlFragments("http://localhost:8080", "/api")
So(result, ShouldEqual, "http://localhost:8080/api")
})
Convey("When joining two urls where righthand side has trailing slash", t, func() {
result := JoinUrlFragments("http://localhost:8080", "api/")
So(result, ShouldEqual, "http://localhost:8080/api/")
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment