@almadar/evaluator 2.11.2 → 2.12.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/dist/index.js CHANGED
@@ -33,7 +33,13 @@ function resolveBinding(binding, ctx) {
33
33
  return void 0;
34
34
  }
35
35
  const withoutPrefix = binding.slice(1);
36
- const parts = withoutPrefix.split(".");
36
+ const parts = withoutPrefix.split(".").flatMap((seg) => {
37
+ const m = seg.match(/^([\w]+)((?:\[\d+\])+)$/);
38
+ if (!m) return [seg];
39
+ const head = m[1];
40
+ const indices = Array.from(m[2].matchAll(/\[(\d+)\]/g)).map((x) => x[1]);
41
+ return [head, ...indices];
42
+ });
37
43
  const root = parts[0];
38
44
  const path = parts.slice(1);
39
45
  if (CLIENT_ONLY_BINDING_ROOTS.has(root)) {
@@ -1204,6 +1210,7 @@ function evalArrayDropLast(args, evaluate2, ctx) {
1204
1210
  }
1205
1211
 
1206
1212
  // std/object.ts
1213
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1207
1214
  function evalLambda(lambdaExpr, evaluate2, ctx, ...values) {
1208
1215
  if (!isSExpr(lambdaExpr) || getOperator(lambdaExpr) !== "fn") {
1209
1216
  return evaluate2(lambdaExpr, ctx);
@@ -1266,6 +1273,9 @@ function evalObjectSet(args, evaluate2, ctx) {
1266
1273
  if (!path) return obj ?? {};
1267
1274
  const result = structuredClone(obj ?? {});
1268
1275
  const parts = path.split(".");
1276
+ if (parts.some((p) => FORBIDDEN_KEYS.has(p))) {
1277
+ return result;
1278
+ }
1269
1279
  let current = result;
1270
1280
  for (let i = 0; i < parts.length - 1; i++) {
1271
1281
  const part = parts[i];
@@ -1303,6 +1313,7 @@ function evalObjectDeepMerge(args, evaluate2, ctx) {
1303
1313
  function deepMerge(target, source) {
1304
1314
  const result = { ...target };
1305
1315
  for (const key of Object.keys(source)) {
1316
+ if (FORBIDDEN_KEYS.has(key)) continue;
1306
1317
  if (source[key] !== null && typeof source[key] === "object" && !Array.isArray(source[key]) && target[key] !== null && typeof target[key] === "object" && !Array.isArray(target[key])) {
1307
1318
  result[key] = deepMerge(
1308
1319
  target[key],