fix: properly decode params in url
Resolves https://kolaente.dev/vikunja/api/issues/1224
This commit is contained in:
parent
382a7884be
commit
8f27e7e619
1 changed files with 20 additions and 0 deletions
|
@ -49,6 +49,7 @@ package routes
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -209,6 +210,25 @@ func registerAPIRoutes(a *echo.Group) {
|
||||||
n := a.Group("")
|
n := a.Group("")
|
||||||
setupRateLimit(n, "ip")
|
setupRateLimit(n, "ip")
|
||||||
|
|
||||||
|
// Echo does not unescape url path params by default. To make sure values bound as :param in urls are passed
|
||||||
|
// properly to handlers, we use this middleware to unescape them.
|
||||||
|
// See https://kolaente.dev/vikunja/api/issues/1224
|
||||||
|
// See https://github.com/labstack/echo/issues/766
|
||||||
|
a.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
return func(c echo.Context) error {
|
||||||
|
params := make([]string, 0, len(c.ParamValues()))
|
||||||
|
for _, param := range c.ParamValues() {
|
||||||
|
p, err := url.PathUnescape(param)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
params = append(params, p)
|
||||||
|
}
|
||||||
|
c.SetParamValues(params...)
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Docs
|
// Docs
|
||||||
n.GET("/docs.json", apiv1.DocsJSON)
|
n.GET("/docs.json", apiv1.DocsJSON)
|
||||||
n.GET("/docs", apiv1.RedocUI)
|
n.GET("/docs", apiv1.RedocUI)
|
||||||
|
|
Loading…
Reference in a new issue