trackoor opened a new issue, #583:
URL: https://github.com/apache/casbin-node-casbin/issues/583
`keyGet2` splits `key1` and `key2` on `/` and returns the segment of `key1`
at the same array index as `:pathVar` in `key2`, which returns the wrong
segment when `/*` spans multiple segments and returns `""` when `:pathVar` is
only part of a segment.
Reproduction (`repro.js`):
```js
const { Util } = require("casbin");
console.log(JSON.stringify(Util.keyGet2Func("/orgs/acme/teams/t1/docs/42",
"/orgs/*/docs/:id", "id")));
console.log(JSON.stringify(Util.keyGet2Func("/files/report-7",
"/files/report-:id", "id")));
```
Run with `node repro.js`.
Actual output:
```
"t1"
""
```
Expected output (matching Go Casbin `util.KeyGet2` and
https://casbin.org/docs/function):
```
"42"
"7"
```
Versions tested: `casbin` 5.51.1 and `master` (`152ccd9`) on Node v26.13.0
(compared against Go Casbin v2.135.0).
In `src/util/builtinOperators.ts`, `keyGet2` checks `keyMatch2(key1, key2)`
and then looks up `keys.indexOf(':' + pathVar)` in `key2.match(/[^/]+/g)`
instead of extracting the capture group matched by `:pathVar` (as Go Casbin
does by replacing `:pathVar` with `([^/]+)` and `/*` with `/.*`).
Credit: https://ucsbplse.github.io/
--
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]