Description

RedirectTrailingSlash not working if there are more than two child route.

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    g := gin.New()
        router := g.Group("/v1")
    router.GET("/hello", dummyFunction)
        router.GET("/hello/a", dummyFunction)
        router.GET("/hello/b", dummyFunction)
    g.Run(":9000")
}

Expectations

$ curl http://localhost:8201/hello/ should redirect [301] to {{URL}}/hello 

Actual result

Getting 404

The same works if there is only one child /hello/a

Environment

  • go version: go version go1.13.3 linux/amd64
  • gin version (or commit ref): v1.5.0
  • operating system: ubuntu 16.04

Comment From: densone

Here's what I think is happening.

/hello/ is returning a 404 because the router knows there are routes that live under /hello/

I guessing the fix would be:

if there are routes under /hello/ and you have a trailing slash, and theres nothing after the trailing slash, redirect.