Merge pull request #4459 from flycash/fix-index
Fix BUG: /abc.html/aaa match /abc/aaa
This commit is contained in:
commit
da498b7df5
@ -1,4 +1,5 @@
|
|||||||
# developing
|
# developing
|
||||||
|
- Fix: /abc.html/aaa match /abc/aaa. [4459](https://github.com/beego/beego/pull/4459)
|
||||||
- ORM mock. [4407](https://github.com/beego/beego/pull/4407)
|
- ORM mock. [4407](https://github.com/beego/beego/pull/4407)
|
||||||
- Add sonar check and ignore test. [4432](https://github.com/beego/beego/pull/4432) [4433](https://github.com/beego/beego/pull/4433)
|
- Add sonar check and ignore test. [4432](https://github.com/beego/beego/pull/4432) [4433](https://github.com/beego/beego/pull/4433)
|
||||||
- Update changlog.yml to check every PR to develop branch.[4427](https://github.com/beego/beego/pull/4427)
|
- Update changlog.yml to check every PR to develop branch.[4427](https://github.com/beego/beego/pull/4427)
|
||||||
|
|||||||
4
go.mod
4
go.mod
@ -12,8 +12,8 @@ require (
|
|||||||
github.com/coreos/go-semver v0.3.0 // indirect
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
||||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
|
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
|
||||||
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17
|
github.com/couchbase/go-couchbase v0.0.0-20210126152612-8e416c37c8ef
|
||||||
github.com/couchbase/gomemcached v0.1.2-0.20201215185628-3bc3f73e68cb // indirect
|
github.com/couchbase/gomemcached v0.1.2-0.20210126151728-840240974836 // indirect
|
||||||
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67 // indirect
|
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67 // indirect
|
||||||
github.com/elastic/go-elasticsearch/v6 v6.8.5
|
github.com/elastic/go-elasticsearch/v6 v6.8.5
|
||||||
github.com/elazarl/go-bindata-assetfs v1.0.0
|
github.com/elazarl/go-bindata-assetfs v1.0.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -42,6 +42,8 @@ github.com/couchbase/go-couchbase v0.0.0-20200519150804-63f3cdb75e0d h1:OMrhQqj1
|
|||||||
github.com/couchbase/go-couchbase v0.0.0-20200519150804-63f3cdb75e0d/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
|
github.com/couchbase/go-couchbase v0.0.0-20200519150804-63f3cdb75e0d/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
|
||||||
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17 h1:1ZELwRDUvpBpmgKSIUP6VMW1jIehzD0sCdWxRyejegw=
|
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17 h1:1ZELwRDUvpBpmgKSIUP6VMW1jIehzD0sCdWxRyejegw=
|
||||||
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17/go.mod h1:+/bddYDxXsf9qt0xpDUtRR47A2GjaXmGGAqQ/k3GJ8A=
|
github.com/couchbase/go-couchbase v0.0.0-20201216133707-c04035124b17/go.mod h1:+/bddYDxXsf9qt0xpDUtRR47A2GjaXmGGAqQ/k3GJ8A=
|
||||||
|
github.com/couchbase/go-couchbase v0.0.0-20210126152612-8e416c37c8ef h1:pXh08kdOlR7eZbHWd7Zvz2KZbI2sxbHRxM+UTWj6oQ0=
|
||||||
|
github.com/couchbase/go-couchbase v0.0.0-20210126152612-8e416c37c8ef/go.mod h1:+/bddYDxXsf9qt0xpDUtRR47A2GjaXmGGAqQ/k3GJ8A=
|
||||||
github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808 h1:8s2l8TVUwMXl6tZMe3+hPCRJ25nQXiA3d1x622JtOqc=
|
github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808 h1:8s2l8TVUwMXl6tZMe3+hPCRJ25nQXiA3d1x622JtOqc=
|
||||||
github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
|
github.com/couchbase/gomemcached v0.0.0-20200526233749-ec430f949808/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
|
||||||
github.com/couchbase/gomemcached v0.1.0 h1:whUde87n8CScx8ckMp2En5liqAlcuG3aKy/BQeBPu84=
|
github.com/couchbase/gomemcached v0.1.0 h1:whUde87n8CScx8ckMp2En5liqAlcuG3aKy/BQeBPu84=
|
||||||
@ -50,6 +52,8 @@ github.com/couchbase/gomemcached v0.1.1 h1:xCS8ZglJDhrlQg3jmK7Rn1V8f7bPjXABLC05C
|
|||||||
github.com/couchbase/gomemcached v0.1.1/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
|
github.com/couchbase/gomemcached v0.1.1/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
|
||||||
github.com/couchbase/gomemcached v0.1.2-0.20201215185628-3bc3f73e68cb h1:ZCFku0K/3Xvl7rXkGGM+ioT76Rxko8V9wDEWa0GFp14=
|
github.com/couchbase/gomemcached v0.1.2-0.20201215185628-3bc3f73e68cb h1:ZCFku0K/3Xvl7rXkGGM+ioT76Rxko8V9wDEWa0GFp14=
|
||||||
github.com/couchbase/gomemcached v0.1.2-0.20201215185628-3bc3f73e68cb/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
|
github.com/couchbase/gomemcached v0.1.2-0.20201215185628-3bc3f73e68cb/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
|
||||||
|
github.com/couchbase/gomemcached v0.1.2-0.20210126151728-840240974836 h1:ZxgtUfduO/Fk2NY1e1YhlgN6tRl0TMdXK9ElddO7uZY=
|
||||||
|
github.com/couchbase/gomemcached v0.1.2-0.20210126151728-840240974836/go.mod h1:mxliKQxOv84gQ0bJWbI+w9Wxdpt9HjDvgW9MjCym5Vo=
|
||||||
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a h1:Y5XsLCEhtEI8qbD9RP3Qlv5FXdTDHxZM9UPUnMRgBp8=
|
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a h1:Y5XsLCEhtEI8qbD9RP3Qlv5FXdTDHxZM9UPUnMRgBp8=
|
||||||
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
|
github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
|
||||||
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67 h1:NCqJ6fwen6YP0WlV/IyibaT0kPt3JEI1rA62V/UPKT4=
|
github.com/couchbase/goutils v0.0.0-20201030094643-5e82bb967e67 h1:NCqJ6fwen6YP0WlV/IyibaT0kPt3JEI1rA62V/UPKT4=
|
||||||
|
|||||||
@ -342,8 +342,9 @@ func (t *Tree) match(treePattern string, pattern string, wildcardValues []string
|
|||||||
if runObject == nil && len(t.fixrouters) > 0 {
|
if runObject == nil && len(t.fixrouters) > 0 {
|
||||||
// Filter the .json .xml .html extension
|
// Filter the .json .xml .html extension
|
||||||
for _, str := range allowSuffixExt {
|
for _, str := range allowSuffixExt {
|
||||||
if strings.HasSuffix(seg, str) {
|
if strings.HasSuffix(seg, str) && strings.HasSuffix(treePattern, seg){
|
||||||
for _, subTree := range t.fixrouters {
|
for _, subTree := range t.fixrouters {
|
||||||
|
// strings.HasSuffix(treePattern, seg) avoid cases: /aaa.html/bbb could access /aaa/bbb
|
||||||
if subTree.prefix == seg[:len(seg)-len(str)] {
|
if subTree.prefix == seg[:len(seg)-len(str)] {
|
||||||
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
runObject = subTree.match(treePattern, pattern, wildcardValues, ctx)
|
||||||
if runObject != nil {
|
if runObject != nil {
|
||||||
|
|||||||
@ -17,6 +17,7 @@ package web
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
@ -49,7 +50,7 @@ func notMatchTestInfo(pattern, url string) testInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
routers = make([]testInfo, 0)
|
routers = make([]testInfo, 0, 128)
|
||||||
// match example
|
// match example
|
||||||
routers = append(routers, matchTestInfo("/topic/?:auth:int", "/topic", nil))
|
routers = append(routers, matchTestInfo("/topic/?:auth:int", "/topic", nil))
|
||||||
routers = append(routers, matchTestInfo("/topic/?:auth:int", "/topic/123", map[string]string{":auth": "123"}))
|
routers = append(routers, matchTestInfo("/topic/?:auth:int", "/topic/123", map[string]string{":auth": "123"}))
|
||||||
@ -108,12 +109,23 @@ func init() {
|
|||||||
routers = append(routers, notMatchTestInfo("/read_:id:int\\.htm", "/read_222_htm"))
|
routers = append(routers, notMatchTestInfo("/read_:id:int\\.htm", "/read_222_htm"))
|
||||||
routers = append(routers, notMatchTestInfo("/read_:id:int\\.htm", " /read_262shtm"))
|
routers = append(routers, notMatchTestInfo("/read_:id:int\\.htm", " /read_262shtm"))
|
||||||
|
|
||||||
|
// test .html, .json not suffix
|
||||||
|
const abcHtml = "/suffix/abc.html"
|
||||||
|
routers = append(routers, notMatchTestInfo(abcHtml, "/suffix.html/abc"))
|
||||||
|
routers = append(routers, matchTestInfo("/suffix/abc", abcHtml, nil))
|
||||||
|
routers = append(routers, matchTestInfo("/suffix/*", abcHtml, nil))
|
||||||
|
routers = append(routers, notMatchTestInfo("/suffix/*", "/suffix.html/a"))
|
||||||
|
const abcSuffix = "/abc/suffix/*"
|
||||||
|
routers = append(routers, notMatchTestInfo(abcSuffix, "/abc/suffix.html/a"))
|
||||||
|
routers = append(routers, matchTestInfo(abcSuffix, "/abc/suffix/a", nil))
|
||||||
|
routers = append(routers, notMatchTestInfo(abcSuffix, "/abc.j/suffix/a"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeRouters(t *testing.T) {
|
func TestTreeRouters(t *testing.T) {
|
||||||
for _, r := range routers {
|
for _, r := range routers {
|
||||||
shouldMatch := r.shouldMatchOrNot
|
|
||||||
|
|
||||||
|
shouldMatch := r.shouldMatchOrNot
|
||||||
tr := NewTree()
|
tr := NewTree()
|
||||||
tr.AddRouter(r.pattern, "astaxie")
|
tr.AddRouter(r.pattern, "astaxie")
|
||||||
ctx := context.NewContext()
|
ctx := context.NewContext()
|
||||||
@ -122,7 +134,7 @@ func TestTreeRouters(t *testing.T) {
|
|||||||
if obj != nil {
|
if obj != nil {
|
||||||
t.Fatal("pattern:", r.pattern, ", should not match", r.requestUrl)
|
t.Fatal("pattern:", r.pattern, ", should not match", r.requestUrl)
|
||||||
} else {
|
} else {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if obj == nil || obj.(string) != "astaxie" {
|
if obj == nil || obj.(string) != "astaxie" {
|
||||||
@ -138,6 +150,7 @@ func TestTreeRouters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStaticPath(t *testing.T) {
|
func TestStaticPath(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user