From 732a83ec6c6aa4ed2f8a90ea7b98ae39d8d530ce Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Wed, 14 Aug 2019 10:33:27 +0300 Subject: [PATCH] minor fix extreme test case on path_test when custom regexp double slashes Former-commit-id: a206cbb72e6740a5e050fae5267848f061efa463 --- core/router/path.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/core/router/path.go b/core/router/path.go index 25a49e85..c70afe84 100644 --- a/core/router/path.go +++ b/core/router/path.go @@ -232,12 +232,32 @@ func splitSubdomainAndPath(fullUnparsedPath string) (subdomain string, path stri } slashIdx := strings.IndexByte(s, '/') - if slashIdx == 0 { - // no subdomain - return "", s // cleanPath(s) + if slashIdx > 0 { + // has subdomain + subdomain = s[0:slashIdx] } - return s[0:slashIdx], s[slashIdx:] // cleanPath(s[slashIdx:]) // return subdomain without slash, path with slash + path = s[slashIdx:] + if !strings.Contains(path, "{") { + path = strings.ReplaceAll(path, "//", "/") + path = strings.ReplaceAll(path, "\\", "/") + } + + // remove any left trailing slashes, i.e "//api/users". + for i := 1; i < len(path); i++ { + if path[i] == '/' { + path = path[0:i] + path[i+1:] + } else { + break + } + } + + // remove last /. + path = strings.TrimRight(path, "/") + + // no cleanPath(path) in order + // to be able to parse macro function regexp(\\). + return // return subdomain without slash, path with slash } // RoutePathReverserOption option signature for the RoutePathReverser.