mirror of
https://github.com/labstack/echo.git
synced 2025-07-05 00:58:47 +02:00
Simplify code of Add/Remove trailing slash and fix bug (#1275)
* Simplify code of Add/Remove trailing slash - simplify code (more informative / understanding) - assert collides with imported package name (in tests) - fix unhandled errors * add tests for https://github.com/labstack/echo/pull/1275#issuecomment-460467700
This commit is contained in:
committed by
Vishal Rana
parent
bc28fceaf3
commit
88965757af
@ -1,6 +1,8 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
@ -49,7 +51,7 @@ func AddTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFunc
|
||||
url := req.URL
|
||||
path := url.Path
|
||||
qs := c.QueryString()
|
||||
if path != "/" && path[len(path)-1] != '/' {
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path += "/"
|
||||
uri := path
|
||||
if qs != "" {
|
||||
@ -97,7 +99,7 @@ func RemoveTrailingSlashWithConfig(config TrailingSlashConfig) echo.MiddlewareFu
|
||||
path := url.Path
|
||||
qs := c.QueryString()
|
||||
l := len(path) - 1
|
||||
if l >= 0 && path != "/" && path[l] == '/' {
|
||||
if l > 0 && strings.HasSuffix(path, "/") {
|
||||
path = path[:l]
|
||||
uri := path
|
||||
if qs != "" {
|
||||
|
Reference in New Issue
Block a user