keyMatch2("/project/1/member", "/project/1") should return false
keyMatch2("/project/1/member", "/project/1") should return false
Hi @heww , thanks for the report.
I saw your commit at: https://github.com/goharbor/harbor/commit/1da0a66fe5b8b5bf1945f1d4a66b1df29bb323bc and used that code. It has been fixed in: https://github.com/casbin/casbin/commit/4aa316fb68d44d4cc5ddd98d7e9ec80bc0a8b081. So you can still use the built-in KeyMatch2() now instead of customizing a function with the HEAD of Casbin.
I do not know why at the beginning keyMatch2("/project/1/member", "/project/1") will return true?
And before the fix, KeyMatch2 will make key /project/:pid/repo/:rid to be used as ^^/project/[^/]+/repo/[^/]+$$ regex. See more https://play.golang.org/p/yF4m0g0fX2w
Not only keyMatch2, and keyMatch3 may have this problem too.
I think more documents needed for keyMatch2 and keyMatch3.
We will update to new release version which included these fix.
Good point. The duplicated starting char and ending char resulted from the for loop:
func KeyMatch2(key1 string, key2 string) bool {
key2 = strings.Replace(key2, "/*", "/.*", -1)
re := regexp.MustCompile(`(.*):[^/]+(.*)`)
for {
if !strings.Contains(key2, "/:") {
break
}
key2 = re.ReplaceAllString(key2, "$1[^/]+$2")
}
return RegexMatch(key1, "^" + key2 + "$")
}
So your fix also had a good shot for this one :)
BTW, I think keyMatch3() doesn't suffer the same issue, see: https://play.golang.org/p/8SG4uoweTvh
FYI, Casbin 1.8.1 has been released: https://github.com/casbin/casbin/releases/tag/v1.8.1
I just run KeyMatch3("/abc", "/") using v1.8.1 and it incorrectly returns true. Should I open a new issue to get this fixed for KeyMatch3 as well?
Hi @dtarico-suplari , please open a new issue and link it to this one if you think they are related.