arshilkxwork opened a new pull request, #1766: URL: https://github.com/apache/casbin/pull/1766
A policy with a malformed regex in a field matched by `regexMatch` (for example `p, alice, /alice_data/*, (GET`) makes `RegexMatchFunc` panic, because it compiles the pattern with `regexp.MustCompile`. `Enforce` recovers the panic, so the process stays up, but the error it returns starts with `panic:` and includes a full goroutine stack trace. `RegexMatchFunc` now compiles through a new `compileOrGet` helper and returns the compile error, wrapped as `regexMatch: error parsing regexp: ...`, the same way it already reports bad argument counts and types. Patterns that fail to compile are not cached. `RegexMatch(key1, key2 string) bool` and the keyMatch2/3/4/5 and keyGet2/3 builders still panic on an invalid pattern. None of them have an error return, and `RegexMatch` is also registered as a role-manager matching function, so changing what it returns for a bad pattern felt like a separate decision. `mustCompileOrGet` keeps the exact panic message it had before. Testing: - New cases in `TestRegexMatchFunc` for unbalanced `[` and `(`. - New `TestEnforceInvalidRegexError` loads `keymatch_model.conf`, adds a policy with `(GET`, and checks that `Enforce` returns a regexMatch parse error with no `panic:` prefix. It fails on master with the stack-trace error. - `go test -race ./...` and `golangci-lint run ./...` pass. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
