Description

If I define the route like *action, there will be an additional character / in the parameters I get.

How to reproduce

I test the example code

func main() {
    router := gin.Default()

    // However, this one will match /user/john/ and also /user/john/send
    // If no other routers match /user/john, it will redirect to /user/john/
    router.GET("/user/:name/*action", func(c *gin.Context) {
        name := c.Param("name")
        action := c.Param("action")
        message := name + " is " + action
        c.String(http.StatusOK, message)
    })

    router.Run(":8080")
}

Expectations

$ curl -i 127.0.0.1:8090/user/admin/running

admin is running

Actual result

$ curl -i 127.0.0.1:8090/user/admin/running

admin is /running

the / is superfluous.

Environment

  • go version: 1.18
  • gin version (or commit ref): 1.8.1
  • operating system: macos(arm64)

Comment From: hyuti

Hi! There are already someone make this clear! Check this old branch! https://github.com/gin-gonic/gin/tree/new-catch-all

Comment From: lcl1024

Hi! There are already someone make this clear! Check this old branch! https://github.com/gin-gonic/gin/tree/new-catch-all

I don't understand what you mean. Even in the old branch, this problem still exists. https://github.com/gin-gonic/gin/blob/new-catch-all/README.md?plain=1#L144

for 127.0.0.1:8090/user/admin/running, I want get running Instead of /running

Comment From: Cookiery

I read the tree.go code seriously. I think it's hard to fix in build tree node process. Maybe you can use strings.Trim(str, "/") in yourself code. Or maybe I can fix it in the func ByName() or func Get().

Comment From: lcl1024

I read the tree.go code seriously. I think it's hard to fix in build tree node process. Maybe you can use strings.Trim(str, "/") in yourself code. Or maybe I can fix it in the func ByName() or func Get().

This only happens when I define the route like *action. This wouldn't have happened if I had used /action

Comment From: Cookiery

Right, because of *action the * is a wildcard. If you use /action it will precise matching. So it wouldn't have happened.

Comment From: appleboy

update the comment in context file.