Skip to content

Commit

Permalink
Fix panic when path is empty (TykTechnologies#3243)
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansenharputlu committed Jul 27, 2020
1 parent 110cdf7 commit 1cc3588
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions gateway/mw_request_signing.go
Expand Up @@ -83,10 +83,9 @@ func (s *RequestSigning) getRequestPath(r *http.Request) string {
} else {
if s.Spec.Proxy.StripListenPath {
path = s.Spec.StripListenPath(r, path)
if path[:1] != "/" {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}

}
}

Expand Down
6 changes: 6 additions & 0 deletions gateway/mw_request_signing_test.go
Expand Up @@ -552,6 +552,12 @@ func TestRequestSigning_getRequestPath(t *testing.T) {
t.Run("StripListenPath=true", func(t *testing.T) {
api.Proxy.StripListenPath = true
assert.Equal(t, "/get?param1=value1", rs.getRequestPath(req))

t.Run("path is empty", func(t *testing.T) {
reqWithEmptyPath, _ := http.NewRequest(http.MethodGet, "http://example.com/test/", nil)
assert.Equal(t, "/", rs.getRequestPath(reqWithEmptyPath))
})

api.Proxy.StripListenPath = false
})

Expand Down

0 comments on commit 1cc3588

Please sign in to comment.