casbin 5.27.0 → 5.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [5.27.1](https://github.com/casbin/node-casbin/compare/v5.27.0...v5.27.1) (2023-09-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * KeyMatch5 does not match the expected result ([#458](https://github.com/casbin/node-casbin/issues/458)) ([0df458d](https://github.com/casbin/node-casbin/commit/0df458dde1f7a061167b978e16e712d208944f39))
7
+
1
8
  # [5.27.0](https://github.com/casbin/node-casbin/compare/v5.26.2...v5.27.0) (2023-08-30)
2
9
 
3
10
 
@@ -208,10 +208,18 @@ exports.keyMatch4Func = keyMatch4Func;
208
208
  // For example, "/foo/bar?status=1&type=2" matches "/foo/bar"
209
209
  function KeyMatch5(key1, key2) {
210
210
  const i = key1.indexOf('?');
211
- if (i === -1) {
212
- return key1 === key2;
211
+ if (i !== -1) {
212
+ key1 = key1.slice(0, i);
213
+ }
214
+ key2 = key2.replace(/\/\*/g, '/.*');
215
+ const regexp = new RegExp(/(.*){[^/]+}(.*)/g);
216
+ for (;;) {
217
+ if (!key2.includes('/{')) {
218
+ break;
219
+ }
220
+ key2 = key2.replace(regexp, '$1[^/]+$2');
213
221
  }
214
- return key1.slice(0, i) === key2;
222
+ return regexMatch(key1, '^' + key2 + '$');
215
223
  }
216
224
  // keyMatch5Func is the wrapper for KeyMatch5.
217
225
  function keyMatch5Func(...args) {
@@ -199,10 +199,18 @@ function keyMatch4Func(...args) {
199
199
  // For example, "/foo/bar?status=1&type=2" matches "/foo/bar"
200
200
  function KeyMatch5(key1, key2) {
201
201
  const i = key1.indexOf('?');
202
- if (i === -1) {
203
- return key1 === key2;
202
+ if (i !== -1) {
203
+ key1 = key1.slice(0, i);
204
+ }
205
+ key2 = key2.replace(/\/\*/g, '/.*');
206
+ const regexp = new RegExp(/(.*){[^/]+}(.*)/g);
207
+ for (;;) {
208
+ if (!key2.includes('/{')) {
209
+ break;
210
+ }
211
+ key2 = key2.replace(regexp, '$1[^/]+$2');
204
212
  }
205
- return key1.slice(0, i) === key2;
213
+ return regexMatch(key1, '^' + key2 + '$');
206
214
  }
207
215
  // keyMatch5Func is the wrapper for KeyMatch5.
208
216
  function keyMatch5Func(...args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casbin",
3
- "version": "5.27.0",
3
+ "version": "5.27.1",
4
4
  "description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS",
5
5
  "main": "lib/cjs/index.js",
6
6
  "typings": "lib/cjs/index.d.ts",