Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

my programme

tree.go

//...
type Param struct {
    Key   string
    Value string
}
//...
func (ps Params) IsEmpty() bool {
    for _, param := range ps {
        if len(param.Value) < 1 {
            return true
        }
    }
    return false
}

gin.go

// Find route in tree
        value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
        if value.params != nil {
            c.Params = *value.params
        }

        if c.Params.IsEmpty() {
            serveError(c, http.StatusNotFound, default404Body)
            return
        }

Of course, I don't think this is the best solution.

Comment From: Bisstocuz

Set Engine.RemoveExtraSlash to true.

Comment From: jincheng9

Are you sure your route rule is /user/:id/action, and you use /user//action to request, and the response is normal? For your case, the repsonse should be 404.

Description

path:/user/:id/action/ if requestUrl=="/user//action"; response normal. I think should response 404 or others.

Comment From: eshine996

Are you sure your route rule is /user/:id/action, and you use /user//action to request, and the response is normal? For your case, the repsonse should be 404.

@jincheng9 I am sure and you can try.

Comment From: eshine996

Set Engine.RemoveExtraSlash to true. @Bisstocuz Thank you. This can solve my problem.but request url=="user/1/////action",it can also parse and response normal.

Comment From: jincheng9

@codeHauler-1 If you set RemoveExtraSlash to true, then your request url well be cleaned to "user/1/action", and it match your route rule "/user/:id/action".

Comment From: eshine996

@codeHauler-1 If you set RemoveExtraSlash to true, then your request url well be cleaned to "user/1/action", and it match your route rule "/user/:id/action".

@jincheng9 thank you.

Comment From: jincheng9

@appleboy @thinkerou @manucorporat please help check whether the following scenarios abide by the gin desgin: All settings are default, and 1. set the route rule "/user/:id/action" 2. request via url "/user//action" result: the gin accepts the url, and gins thinks the param id is empty string, and return 200. I think the response should be 404.

but if we do this: 1. set the route rule "/user/:id/action" 2. request via url "/user//action/" result: the response is 404. It seems the trailing slash redirect does not work.

Please help clarify the desgin. thanks.

Comment From: eshine996

Has this problem been fixed? Or it goes against gin's design @jincheng9

Comment From: jincheng9

I think it's a bug. I will fix it later. Currently you can check and avoid invalid url request in your logic code.

Comment From: eshine996

Has this problem been fixed? @jincheng9