Repository navigation
fix: read keyGet2 values from the matched capture groups - #584
Merged
Merged
Conversation
keyGet2 took the segment of key1 at the same split index as :pathVar in key2. That is wrong when /* spans more than one segment, and it gives "" when :pathVar is only part of a segment (/files/report-:id). Now it builds the regex like Go Casbin's KeyGet2 (/* -> /.*, :name -> ([^/]+)) and returns the capture group of :pathVar. Fixes #583
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #584 +/- ##
=========================================
Coverage ? 71.40%
=========================================
Files ? 34
Lines ? 2207
Branches ? 518
=========================================
Hits ? 1576
Misses ? 380
Partials ? 251
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #583
keyGet2splitkey1andkey2on/and returned the segment ofkey1at the same index as:pathVarinkey2. So:/*that spans more than one segment shifted the index:keyGet2('/orgs/acme/teams/t1/docs/42', '/orgs/*/docs/:id', 'id')gavet1.:pathVarinside a segment never matched (keyMatch2only expands/:):keyGet2('/files/report-7', '/files/report-:id', 'id')gave"".Now
keyGet2builds the regex the same way Go Casbin'sutil.KeyGet2does (/*→/.*,:name→([^/]+)) and returns the capture group of:pathVar. A bare*pattern still gives""and does not throw.Testing
test/util.test.tsfail before (Expected "42", Received "t1") and pass after.*) through Go Casbin v2.135.0util.KeyGet2: the new code gives the same result for all 22, the old code differed on 4.jest(17 suites, 239 passed),eslint . --ext .js,.ts, prettier,npm run buildclean.