casbin 5.26.0 → 5.26.2

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,17 @@
1
+ ## [5.26.2](https://github.com/casbin/node-casbin/compare/v5.26.1...v5.26.2) (2023-07-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add escapeCsv() for CSV file saving ([17c542a](https://github.com/casbin/node-casbin/commit/17c542ad894cc19b592e3c54495fb05eff02f215))
7
+
8
+ ## [5.26.1](https://github.com/casbin/node-casbin/compare/v5.26.0...v5.26.1) (2023-03-29)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * escapeAssertion is compatible with safari ([#444](https://github.com/casbin/node-casbin/issues/444)) ([d13a3b9](https://github.com/casbin/node-casbin/commit/d13a3b9030da1603f746dd20bc93354df81b182a))
14
+
1
15
  # [5.26.0](https://github.com/casbin/node-casbin/compare/v5.25.0...v5.26.0) (2023-03-26)
2
16
 
3
17
 
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![GitHub Actions](https://github.com/casbin/node-casbin/workflows/main/badge.svg)](https://github.com/casbin/node-casbin/actions)
8
8
  [![Coverage Status](https://coveralls.io/repos/github/casbin/node-casbin/badge.svg?branch=master)](https://coveralls.io/github/casbin/node-casbin?branch=master)
9
9
  [![Release](https://img.shields.io/github/release/casbin/node-casbin.svg)](https://github.com/casbin/node-casbin/releases/latest)
10
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/casbin/lobby)
10
+ [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)
11
11
 
12
12
  [npm-image]: https://img.shields.io/npm/v/casbin.svg?style=flat-square
13
13
  [npm-url]: https://npmjs.org/package/casbin
@@ -21,6 +21,7 @@ export declare class FileAdapter implements Adapter {
21
21
  * savePolicy saves all policy rules to the storage.
22
22
  */
23
23
  savePolicy(model: Model): Promise<boolean>;
24
+ private escapeCsv;
24
25
  private savePolicyFile;
25
26
  /**
26
27
  * addPolicy adds a policy rule to the storage.
@@ -63,13 +63,20 @@ class FileAdapter {
63
63
  gList.forEach((n) => {
64
64
  n.policy.forEach((m) => {
65
65
  result += n.key + ', ';
66
- result += util_1.arrayToString(m);
66
+ result += util_1.arrayToString(m.map((element) => this.escapeCsv(element)));
67
67
  result += '\n';
68
68
  });
69
69
  });
70
70
  await this.savePolicyFile(result.trim());
71
71
  return true;
72
72
  }
73
+ escapeCsv(value) {
74
+ // If the value contains a comma, wrap it in double quotes and escape any existing double quotes
75
+ if (value.includes(',')) {
76
+ return `"${value.replace(/"/g, '""')}"`;
77
+ }
78
+ return value;
79
+ }
73
80
  async savePolicyFile(text) {
74
81
  (this.fs ? this.fs : fileSystem_1.mustGetDefaultFileSystem()).writeFileSync(this.filePath, text);
75
82
  }
@@ -17,12 +17,10 @@ exports.bracketCompatible = exports.customIn = exports.deepCopy = exports.genera
17
17
  // escapeAssertion escapes the dots in the assertion,
18
18
  // because the expression evaluation doesn't support such variable names.
19
19
  const persist_1 = require("../persist");
20
+ const escapeAssertionReg = new RegExp(/(^|[^A-Za-z0-9_])([rp])[0-9]*\./g);
20
21
  function escapeAssertion(s) {
21
- s = s.replace(/(?<!\w)r[0-9]*\./g, (match) => {
22
- return match.replace('.', '_');
23
- });
24
- s = s.replace(/(?<!\w)p[0-9]*\./g, (match) => {
25
- return match.replace('.', '_');
22
+ s = s.replace(escapeAssertionReg, (match, p1, p2) => {
23
+ return p1 + p2 + match.substring(p1.length + p2.length).replace('.', '_');
26
24
  });
27
25
  return s;
28
26
  }
@@ -21,6 +21,7 @@ export declare class FileAdapter implements Adapter {
21
21
  * savePolicy saves all policy rules to the storage.
22
22
  */
23
23
  savePolicy(model: Model): Promise<boolean>;
24
+ private escapeCsv;
24
25
  private savePolicyFile;
25
26
  /**
26
27
  * addPolicy adds a policy rule to the storage.
@@ -60,13 +60,20 @@ export class FileAdapter {
60
60
  gList.forEach((n) => {
61
61
  n.policy.forEach((m) => {
62
62
  result += n.key + ', ';
63
- result += arrayToString(m);
63
+ result += arrayToString(m.map((element) => this.escapeCsv(element)));
64
64
  result += '\n';
65
65
  });
66
66
  });
67
67
  await this.savePolicyFile(result.trim());
68
68
  return true;
69
69
  }
70
+ escapeCsv(value) {
71
+ // If the value contains a comma, wrap it in double quotes and escape any existing double quotes
72
+ if (value.includes(',')) {
73
+ return `"${value.replace(/"/g, '""')}"`;
74
+ }
75
+ return value;
76
+ }
70
77
  async savePolicyFile(text) {
71
78
  (this.fs ? this.fs : mustGetDefaultFileSystem()).writeFileSync(this.filePath, text);
72
79
  }
@@ -14,12 +14,10 @@
14
14
  // escapeAssertion escapes the dots in the assertion,
15
15
  // because the expression evaluation doesn't support such variable names.
16
16
  import { mustGetDefaultFileSystem } from '../persist';
17
+ const escapeAssertionReg = new RegExp(/(^|[^A-Za-z0-9_])([rp])[0-9]*\./g);
17
18
  function escapeAssertion(s) {
18
- s = s.replace(/(?<!\w)r[0-9]*\./g, (match) => {
19
- return match.replace('.', '_');
20
- });
21
- s = s.replace(/(?<!\w)p[0-9]*\./g, (match) => {
22
- return match.replace('.', '_');
19
+ s = s.replace(escapeAssertionReg, (match, p1, p2) => {
20
+ return p1 + p2 + match.substring(p1.length + p2.length).replace('.', '_');
23
21
  });
24
22
  return s;
25
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casbin",
3
- "version": "5.26.0",
3
+ "version": "5.26.2",
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",