-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
value.tsr cause wrong redirect #2843
Comments
Could you provide an example? prefix[len(path)] // panic |
It won't panic. The code in screenshot is to determine whether a leaf exists for the same URL with an external trailing slash. For example, for path |
Could you provide an example? Something like this package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.New()
fmt.Println(gin.Version)
server := &http.Server{
Addr: ":8080",
Handler: router,
}
router.GET("/", func(c *gin.Context) {
c.String(200, c.ClientIP())
})
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
} When I changed the code, I removed it because there was a panic. But I did not record the problem of panic. -_ - |
package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.New()
fmt.Println(gin.Version)
server := &http.Server{
Addr: ":8080",
Handler: router,
}
router.NoRoute(func(c *gin.Context) {
if c.Request.RequestURI == "/login" {
c.String(200, "Enter NoRoute. Path: login")
}
})
router.GET("/logout", func(c *gin.Context) {
c.String(200, "logout")
})
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
} Visit Tip: Clean brower cache or open a private windows, after switching v1.7.4 to v1.7.2 In addition, I could not understand how |
Ok, thank you for the example you provided. I am a little busy these two days, so I will test it on Sunday 💗 |
|
@Zeahow Yes, there will be a suffix '/' at the end of the match, can you submit a PR to fix this problem? And add test example, thanks. |
fixed in #2847 |
Version: v1.7.4
After upgrading the version from
v1.7.2
tov1.7.4
, the logic ofvalue.tsr
has changed. Some cases that should return false will return true now.I register a handler with path
logout
, while pathlogin
is handled inNoRouter
handler. Onlylogin
will be handled inNoRouter
.NoRouter
will return404
if path islogin/
.In v1.7.2
login
will enterNoRouter
, and it will be handled. But in v1.7.4,value.tsr
will betrue
so that the request will be rediredcted tologin/
which will return404
.The text was updated successfully, but these errors were encountered: