Skip to content

Commit 9d7a748

Browse files
Shaisolarisbrettz9
authored andcommitted
fix(safe eval): support the ?? and ** operators
jsep parses ?? and ** but the safe evaluator's operator table had no entry for them, so a filter such as $..[?((@.price ?? 0) > 10)] failed with "Unknown binary operator: ??" under the default eval: "safe" while eval: "native" handled it. ?? keeps short-circuiting on its right side like || and &&.
1 parent f294eb9 commit 9d7a748

11 files changed

Lines changed: 22 additions & 10 deletions

‎badges/tests-badge.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎dist/index-browser-esm.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ const getSafeProperty = (obj, prop) => {
12791279
// eslint-disable-next-line @stylistic/max-len -- Long
12801280
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
12811281
'||': (a, b) => a || b(),
1282+
'??': (a, b) => a ?? b(),
12821283
'&&': (a, b) => a && b(),
12831284
'|': (a, b) => a | b(),
12841285
'^': (a, b) => a ^ b(),
@@ -1300,7 +1301,8 @@ const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
13001301
'-': (a, b) => a - b(),
13011302
'*': (a, b) => a * b(),
13021303
'/': (a, b) => a / b(),
1303-
'%': (a, b) => a % b()
1304+
'%': (a, b) => a % b(),
1305+
'**': (a, b) => a ** b()
13041306
});
13051307

13061308
/**

‎dist/index-browser-esm.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-esm.min.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-umd.cjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@
12851285
// eslint-disable-next-line @stylistic/max-len -- Long
12861286
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
12871287
'||': (a, b) => a || b(),
1288+
'??': (a, b) => a ?? b(),
12881289
'&&': (a, b) => a && b(),
12891290
'|': (a, b) => a | b(),
12901291
'^': (a, b) => a ^ b(),
@@ -1306,7 +1307,8 @@
13061307
'-': (a, b) => a - b(),
13071308
'*': (a, b) => a * b(),
13081309
'/': (a, b) => a / b(),
1309-
'%': (a, b) => a % b()
1310+
'%': (a, b) => a % b(),
1311+
'**': (a, b) => a ** b()
13101312
});
13111313

13121314
/**

‎dist/index-browser-umd.min.cjs‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎dist/index-browser-umd.min.cjs.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-node-cjs.cjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ const getSafeProperty = (obj, prop) => {
12831283
// eslint-disable-next-line @stylistic/max-len -- Long
12841284
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
12851285
'||': (a, b) => a || b(),
1286+
'??': (a, b) => a ?? b(),
12861287
'&&': (a, b) => a && b(),
12871288
'|': (a, b) => a | b(),
12881289
'^': (a, b) => a ^ b(),
@@ -1304,7 +1305,8 @@ const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
13041305
'-': (a, b) => a - b(),
13051306
'*': (a, b) => a * b(),
13061307
'/': (a, b) => a / b(),
1307-
'%': (a, b) => a % b()
1308+
'%': (a, b) => a % b(),
1309+
'**': (a, b) => a ** b()
13081310
});
13091311

13101312
/**

‎dist/index-node-esm.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,7 @@ const getSafeProperty = (obj, prop) => {
12811281
// eslint-disable-next-line @stylistic/max-len -- Long
12821282
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
12831283
'||': (a, b) => a || b(),
1284+
'??': (a, b) => a ?? b(),
12841285
'&&': (a, b) => a && b(),
12851286
'|': (a, b) => a | b(),
12861287
'^': (a, b) => a ^ b(),
@@ -1302,7 +1303,8 @@ const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */{
13021303
'-': (a, b) => a - b(),
13031304
'*': (a, b) => a * b(),
13041305
'/': (a, b) => a / b(),
1305-
'%': (a, b) => a % b()
1306+
'%': (a, b) => a % b(),
1307+
'**': (a, b) => a ** b()
13061308
});
13071309

13081310
/**

‎src/Safe-Script.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const getSafeProperty = (obj, prop) => {
107107
// eslint-disable-next-line @stylistic/max-len -- Long
108108
const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */ ({
109109
'||': (a, b) => a || b(),
110+
'??': (a, b) => a ?? b(),
110111
'&&': (a, b) => a && b(),
111112
'|': (a, b) => a | b(),
112113
'^': (a, b) => a ^ b(),
@@ -128,7 +129,8 @@ const BINOPS = Object.assign(Object.create(null), /** @type {OperatorTable} */ (
128129
'-': (a, b) => a - b(),
129130
'*': (a, b) => a * b(),
130131
'/': (a, b) => a / b(),
131-
'%': (a, b) => a % b()
132+
'%': (a, b) => a % b(),
133+
'**': (a, b) => a ** b()
132134
}));
133135

134136
/**

0 commit comments

Comments
 (0)