You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Rewrite requests without version to use v1
e.Pre(echomiddleware.Rewrite(map[string]string{
"^/abc/*": "/v1/abc/$1",
}))
where ^ is regexp for beginning of string.
Some examples before and what they got mapped to:
/abc/test -> /v1/abc/test
/v1/abc/test (same, no rewrite)
/v2/abc/test (same, no rewrite)
Actual behaviour
The new versions re-formats the beginning of line character using regexp.QuoteMeta so it can't be used anymore. Rewrite will change ANY "version prefix" to v1 if removing "^", not just ones without it, e.g.:
which is not what we intended and breaks backwards compatibility.
Steps to reproduce
Working code to debug
package main
import(
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
)
funcmain() {
e:=echo.New()
// Rewrite requests without version to use v1.// This worked on v4.1.13 but now nothing matches until removing the ^ here.// However, that makes it match in the middle of strings.e.Pre(echomiddleware.Rewrite(map[string]string{
"^/abc/*": "/v1/abc/$1",
}))
group:=e.Group("")
group.Use(echomiddleware.Logger())
group.Any("/v1/abc/test", func(c echo.Context) error {
returnc.String(http.StatusOK, "Route: /v1/abc/test")
})
e.Logger.Fatal(e.StartServer(e.Server))
}
Version/commit
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Issue Description
Rewrite middleware was changed in v4.1.16 here:
5428358
After this change it seems it's not possible to explicitly match beginning of path anymore.
Checklist
Expected behaviour
Before we were using this:
where ^ is regexp for beginning of string.
Some examples before and what they got mapped to:
Actual behaviour
The new versions re-formats the beginning of line character using regexp.QuoteMeta so it can't be used anymore. Rewrite will change ANY "version prefix" to v1 if removing "^", not just ones without it, e.g.:
which is not what we intended and breaks backwards compatibility.
Steps to reproduce
Working code to debug
Version/commit
The text was updated successfully, but these errors were encountered: