Skip to content

fix: compare repeated keyMatch4 tokens only with their own values - #574

Merged
hsluoyz merged 1 commit into
apache:masterfrom
basitalisandhu:fix-keymatch4-repeated-tokens
Oct 27, 2026
Merged

hsluoyz merged 1 commit into
apache:masterfrom
basitalisandhu:fix-keymatch4-repeated-tokens

Conversation

@basitalisandhu

@basitalisandhu basitalisandhu commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

keyMatch4 groups captured values by token name, but the repeated-token loop compares every captured value (values) with the first one instead of that token's own group (value), see src/util/builtinOperators.ts L226-233. So a pattern with a repeated token plus any other token rejects valid paths:

Util.keyMatch4Func('/parent/123/child/123/book/456', '/parent/{id}/child/{id}/book/{book_id}') // false, expected true
Util.keyMatch4Func('/org/1/user/2/org/1', '/org/{org}/user/{user}/org/{org}')                 // false, expected true

Go Casbin's KeyMatch4 compares each token only with its own earlier value and returns true for both.

Now values are compared within each token group. The new cases in test/util.test.ts fail before (expected true, received false) and pass after; existing keyMatch4 cases still pass. jest (17 suites, 239 passed, conformance skipped), eslint . --ext .js,.ts, pretty-quick and npm run build are clean.

keyMatch4 grouped the captured values by token name, but the check for a
repeated token then compared every captured value with the first one. Any
pattern with a repeated token plus another token rejected valid paths, for
example /parent/123/child/123/book/456 against
/parent/{id}/child/{id}/book/{book_id}. Compare the values within each
token group instead, as Go Casbin does.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@7dbadda). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #574   +/-   ##
=========================================
  Coverage          ?   71.30%           
=========================================
  Files             ?       34           
  Lines             ?     2206           
  Branches          ?      517           
=========================================
  Hits              ?     1573           
  Misses            ?      381           
  Partials          ?      252           
Flag Coverage Δ
node-^20 71.30% <100.00%> (?)
node-^22 71.30% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hsluoyz
hsluoyz merged commit 152ccd9 into apache:master Oct 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants