hidingmyname opened a new issue, #275: URL: https://github.com/apache/casbin-cpp/issues/275
## Use case Casbin's [function reference](https://casbin.apache.org/docs/function/) lists `keyMatch5`: arg1 is "a URL path like `/alice_data/123/?status=1`", arg2 is "a URL path, a `{}` or `*` pattern like `/alice_data/{id}/*`". The query string of the request path is ignored when matching. A model that uses it in the Go implementation, e.g. ```ini [matchers] m = r.sub == p.sub && keyMatch5(r.obj, p.obj) && r.act == p.act ``` with `p, alice, /parent/child, GET`, can't be used unchanged with casbin-cpp. Users have to strip the query string themselves or register their own function. ## Current behavior casbin-cpp registers `keyMatch` … `keyMatch4`, `regexMatch`, `ipMatch` and `keyGet*` as built-ins, but not `keyMatch5` ([`ExprtkEvaluator::LoadFunctions`](https://github.com/apache/casbin-cpp/blob/0ad64a739bd841099c6dbbae4a1f60d12e6cbc0a/casbin/model/evaluator.cpp#L81-L91)). A matcher that calls it fails to evaluate: on master [`0ad64a7`](https://github.com/apache/casbin-cpp/commit/0ad64a739bd841099c6dbbae4a1f60d12e6cbc0a) (current HEAD when written), the first `Enforce` call throws, and gtest reports: ```text unknown file: Failure Unknown C++ exception thrown in the test body. ``` So an unknown function is already an error, not an allow. This request is only about adding the missing function. ## Proposed behavior and scope Add a `keyMatch5(key1, key2)` built-in with the same semantics as the reference implementation ([apache/casbin `KeyMatch5`](https://github.com/apache/casbin/blob/c35c93d29063b8bc3bc2ef30b09943d344a289f4/util/builtin_operators.go#L477-L509)): drop everything from the first `?` in `key1`, then match against `key2` where `/*` is a wildcard and `{name}` matches one path segment. Expected results for the example above: | request obj | policy obj | result | | --- | --- | --- | | `/parent/child?status=1&type=2` | `/parent/child` | true | | `/parent?status=1&type=2` | `/parent/child` | false | | `/parent/child/?status=1&type=2` | `/parent/child` | false | Unchanged: the other built-ins, how unknown functions are reported, and the result of models that don't use `keyMatch5`. ## Alternatives - Register a custom function via `AddFunction` in each application. - Pre-process `r.obj` to strip the query string before calling `Enforce`, then use `keyMatch4`/`keyMatch2`. ## Related issues checked No issue/PR mentions `keyMatch5`. #209 / #212 added the then-missing `keyGet*` / `keyMatch4` built-ins in the same way. This is the next function in that list. -- 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]
