@posiwise/common-services 0.1.99 → 0.2.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.
|
@@ -1489,10 +1489,8 @@ class PermissionService {
|
|
|
1489
1489
|
return true;
|
|
1490
1490
|
if (expr === 'false')
|
|
1491
1491
|
return false;
|
|
1492
|
-
// Recursively simplify: split on lowest-precedence operator at depth 0
|
|
1493
|
-
// || has lower precedence than && in JS
|
|
1494
1492
|
let depth = 0;
|
|
1495
|
-
for (let i = 0; i
|
|
1493
|
+
for (let i = 0; i < expr.length - 1; i++) {
|
|
1496
1494
|
const c = expr[i];
|
|
1497
1495
|
if (c === '(')
|
|
1498
1496
|
depth++;
|
|
@@ -1505,7 +1503,7 @@ class PermissionService {
|
|
|
1505
1503
|
}
|
|
1506
1504
|
}
|
|
1507
1505
|
depth = 0;
|
|
1508
|
-
for (let i = 0; i
|
|
1506
|
+
for (let i = 0; i < expr.length - 1; i++) {
|
|
1509
1507
|
const c = expr[i];
|
|
1510
1508
|
if (c === '(')
|
|
1511
1509
|
depth++;
|
|
@@ -1517,18 +1515,23 @@ class PermissionService {
|
|
|
1517
1515
|
return (this.evaluateBooleanExpression(left) && this.evaluateBooleanExpression(right));
|
|
1518
1516
|
}
|
|
1519
1517
|
}
|
|
1520
|
-
// Strip matching outer parens
|
|
1518
|
+
// Strip matching outer parens - only when first ( and last ) are a pair
|
|
1521
1519
|
if (expr.startsWith('(') && expr.endsWith(')')) {
|
|
1522
|
-
let
|
|
1523
|
-
for (let j =
|
|
1520
|
+
let depth = 0;
|
|
1521
|
+
for (let j = 0; j < expr.length; j++) {
|
|
1524
1522
|
if (expr[j] === '(')
|
|
1525
|
-
|
|
1526
|
-
if (expr[j] === ')')
|
|
1527
|
-
|
|
1528
|
-
if (
|
|
1529
|
-
|
|
1523
|
+
depth++;
|
|
1524
|
+
else if (expr[j] === ')')
|
|
1525
|
+
depth--;
|
|
1526
|
+
if (depth === 0) {
|
|
1527
|
+
if (j === expr.length - 1) {
|
|
1528
|
+
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1529
|
+
}
|
|
1530
|
+
break; // First ( doesn't wrap entire expr
|
|
1531
|
+
}
|
|
1532
|
+
if (depth < 0)
|
|
1533
|
+
break;
|
|
1530
1534
|
}
|
|
1531
|
-
return this.evaluateBooleanExpression(expr.substring(1, expr.length - 1));
|
|
1532
1535
|
}
|
|
1533
1536
|
// Unrecognized token - treat as false for safety
|
|
1534
1537
|
return false;
|
|
@@ -1537,8 +1540,6 @@ class PermissionService {
|
|
|
1537
1540
|
if (typeof permission !== 'boolean') {
|
|
1538
1541
|
permission.split(' ').forEach(x => {
|
|
1539
1542
|
const raw = x.trim();
|
|
1540
|
-
if (!raw)
|
|
1541
|
-
return; // Skip empty tokens (e.g. from double spaces) - avoids malformed expr
|
|
1542
1543
|
if (['||', '&&', '(', ')'].includes(raw)) {
|
|
1543
1544
|
expr += ` ${raw} `;
|
|
1544
1545
|
}
|