@poe-platform/safe-js 0.1.182 → 0.1.184

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.
@@ -27,7 +27,7 @@ import {
27
27
  validateMigrationSemantics,
28
28
  validateSnapshotData,
29
29
  validateSnapshotMigration
30
- } from "./chunk-A6KP64IV.js";
30
+ } from "./chunk-Q64VTJKF.js";
31
31
 
32
32
  // packages/safe-js/src/migrate.ts
33
33
  import { createHash } from "node:crypto";
@@ -8249,4 +8249,4 @@ export {
8249
8249
  parseMcpConfig,
8250
8250
  makeMcpModule
8251
8251
  };
8252
- //# sourceMappingURL=chunk-J5JNS3B3.js.map
8252
+ //# sourceMappingURL=chunk-4XA4KLMD.js.map
@@ -10827,23 +10827,28 @@ function callReplaceLikeMethod(value, methodName, args, budget, callClosure, use
10827
10827
  replacement,
10828
10828
  methodName === "replaceAll",
10829
10829
  budget,
10830
- callClosure
10830
+ callClosure,
10831
+ context
10831
10832
  );
10832
10833
  }
10833
10834
  async function replaceRegex(value, regex, replacement, budget, callClosure, context) {
10835
+ if (["exec", "flags", ...Object.keys(regexFlagProperties)].some((key) => getSandboxPropertyDescriptor(regex, key, budget) !== void 0))
10836
+ return replaceObservableRegex(value, regex, replacement, budget, callClosure, context);
10834
10837
  if (regex.flags.includes("g")) regex.lastIndex = 0;
10835
10838
  const cursor = regex.lastIndex;
10839
+ let result = "";
10836
10840
  const retained = {};
10837
- budget.setRetainedValues(retained, () => [value, regex, cursor, replacement]);
10841
+ budget.setRetainedValues(retained, () => [value, regex, cursor, replacement, result]);
10838
10842
  try {
10839
10843
  const lastIndex = await sandboxNumber(cursor, budget, context);
10840
10844
  const matches = collectRegexMatches(regex, value, regex.flags.includes("g"), void 0, lastIndex);
10841
- let result = "";
10842
10845
  let copiedThrough = 0;
10843
10846
  for (const match of matches) {
10844
10847
  result += value.slice(copiedThrough, match.index);
10845
- result += typeof replacement === "string" ? expandReplacement(replacement, match.text, match.captures, value, match.index) : String(
10846
- await callClosure(replacement, [match.text, ...match.captures, match.index, value])
10848
+ result += typeof replacement === "string" ? await expandReplacement(replacement, match.text, match.captures, value, match.index, budget, context) : await sandboxString(
10849
+ await callClosure(replacement, [match.text, ...match.captures, match.index, value]),
10850
+ budget,
10851
+ context
10847
10852
  );
10848
10853
  copiedThrough = match.index + match.text.length;
10849
10854
  }
@@ -10853,57 +10858,171 @@ async function replaceRegex(value, regex, replacement, budget, callClosure, cont
10853
10858
  budget.setRetainedValues(retained, void 0);
10854
10859
  }
10855
10860
  }
10856
- function expandReplacement(replacement, match, captures, input, matchIndex) {
10861
+ function readReplacementProperty(target, key, budget, context) {
10862
+ if (context?.getProperty !== void 0) return context.getProperty(target, key);
10863
+ const descriptor = getSandboxPropertyDescriptor(target, key, budget);
10864
+ if (descriptor !== void 0) return readPropertyDescriptor(descriptor, target, context);
10865
+ return isSandboxRegex(target) ? getRegexMember(target, key, budget, context) : void 0;
10866
+ }
10867
+ async function replaceObservableRegex(value, regex, replacement, budget, callClosure, context) {
10868
+ const matches = [];
10869
+ let current;
10870
+ let field;
10871
+ let groups;
10872
+ let matched;
10873
+ let captures = [];
10857
10874
  let result = "";
10858
- for (let index = 0; index < replacement.length; index += 1) {
10859
- const character = replacement.charAt(index);
10860
- if (character !== "$") {
10861
- result += character;
10862
- continue;
10875
+ let flags;
10876
+ const release = retainValues(budget, () => [value, regex, replacement, matches, current, field, groups, matched, captures, result, flags]);
10877
+ try {
10878
+ field = await readReplacementProperty(regex, "flags", budget, context);
10879
+ flags = await sandboxString(field, budget, context);
10880
+ field = void 0;
10881
+ const global = flags.includes("g");
10882
+ const fullUnicode = flags.includes("u") || flags.includes("v");
10883
+ flags = void 0;
10884
+ if (global) regex.lastIndex = 0;
10885
+ while (true) {
10886
+ budget.visitNode();
10887
+ current = await regexExec(regex, value, budget, context);
10888
+ if (current === null) break;
10889
+ budget.allocateArrayLength(matches.length + 1);
10890
+ matches.push(current);
10891
+ if (!global) break;
10892
+ field = await readReplacementProperty(current, "0", budget, context);
10893
+ matched = await sandboxString(field, budget, context);
10894
+ field = void 0;
10895
+ if (matched.length === 0) {
10896
+ field = regex.lastIndex;
10897
+ const index = normalizeLastIndex(await sandboxNumber(field, budget, context));
10898
+ const point = fullUnicode ? value.codePointAt(index) : void 0;
10899
+ regex.lastIndex = index + (point !== void 0 && point > 65535 ? 2 : 1);
10900
+ field = void 0;
10901
+ }
10902
+ matched = void 0;
10903
+ current = void 0;
10863
10904
  }
10864
- const token = replacement.charAt(index + 1);
10865
- if (token === "$") {
10866
- result += "$";
10867
- } else if (token === "&") {
10868
- result += match;
10869
- } else if (token === "`") {
10870
- result += input.slice(0, matchIndex);
10871
- } else if (token === "'") {
10872
- result += input.slice(matchIndex + match.length);
10873
- } else if (token >= "0" && token <= "9") {
10874
- let captureIndex = Number(token);
10875
- const nextDigit = replacement.charAt(index + 2);
10876
- if (nextDigit >= "0" && nextDigit <= "9") {
10877
- const twoDigitIndex = Number(token + nextDigit);
10878
- if (twoDigitIndex > 0 && twoDigitIndex <= captures.length) {
10879
- captureIndex = twoDigitIndex;
10880
- index += 1;
10881
- }
10905
+ let copiedThrough = 0;
10906
+ for (current of matches) {
10907
+ field = await readReplacementProperty(current, "length", budget, context);
10908
+ const count = Math.max(normalizeLastIndex(await sandboxNumber(field, budget, context)) - 1, 0);
10909
+ field = await readReplacementProperty(current, "0", budget, context);
10910
+ matched = await sandboxString(field, budget, context);
10911
+ field = await readReplacementProperty(current, "index", budget, context);
10912
+ const number = await sandboxNumber(field, budget, context);
10913
+ const position = Math.min(Math.max(Number.isNaN(number) ? 0 : Math.trunc(number), 0), value.length);
10914
+ field = void 0;
10915
+ captures = [];
10916
+ budget.allocateArrayLength(count);
10917
+ for (let index = 1; index <= count; index++) {
10918
+ budget.visitNode();
10919
+ field = await readReplacementProperty(current, String(index), budget, context);
10920
+ captures.push(field === void 0 ? void 0 : await sandboxString(field, budget, context));
10921
+ field = void 0;
10922
+ }
10923
+ groups = await readReplacementProperty(current, "groups", budget, context);
10924
+ let text;
10925
+ if (typeof replacement === "string") {
10926
+ if (groups === null) throw new TypeError("Replacement groups cannot be null.");
10927
+ if (groups !== void 0 && typeof groups !== "object") {
10928
+ groups = createSandboxBox(groups);
10929
+ budget.chargeDataUsage(measureSandboxData([groups]));
10930
+ }
10931
+ text = await expandReplacement(replacement, matched, captures, value, position, budget, context, groups);
10932
+ } else {
10933
+ const args = [matched, ...captures, position, value];
10934
+ if (groups !== void 0) args.push(groups);
10935
+ budget.allocateArrayLength(args.length);
10936
+ field = await callClosure(replacement, args);
10937
+ text = await sandboxString(field, budget, context);
10938
+ field = void 0;
10939
+ }
10940
+ if (position >= copiedThrough) {
10941
+ result = budget.allocateString(result + value.slice(copiedThrough, position) + text);
10942
+ copiedThrough = position + matched.length;
10882
10943
  }
10883
- if (captureIndex === 0 || captureIndex > captures.length) {
10944
+ matched = void 0;
10945
+ captures = [];
10946
+ groups = void 0;
10947
+ }
10948
+ return budget.allocateString(result + value.slice(copiedThrough));
10949
+ } finally {
10950
+ release();
10951
+ }
10952
+ }
10953
+ async function expandReplacement(replacement, match, captures, input, matchIndex, budget, context, groups) {
10954
+ let result = "";
10955
+ const release = retainValues(budget, () => [replacement, match, captures, input, groups, result]);
10956
+ try {
10957
+ for (let index = 0; index < replacement.length; index += 1) {
10958
+ budget.visitNode();
10959
+ budget.allocateString(result);
10960
+ const character = replacement.charAt(index);
10961
+ if (character !== "$") {
10962
+ result += character;
10963
+ continue;
10964
+ }
10965
+ const token = replacement.charAt(index + 1);
10966
+ if (token === "$") {
10967
+ result += "$";
10968
+ } else if (token === "&") {
10969
+ result += match;
10970
+ } else if (token === "`") {
10971
+ result += input.slice(0, matchIndex);
10972
+ } else if (token === "'") {
10973
+ result += input.slice(matchIndex + match.length);
10974
+ } else if (token === "<" && groups !== void 0) {
10975
+ const end = replacement.indexOf(">", index + 2);
10976
+ if (end === -1) {
10977
+ result += "$";
10978
+ continue;
10979
+ }
10980
+ const capture = await readReplacementProperty(groups, replacement.slice(index + 2, end), budget, context);
10981
+ if (capture !== void 0) result += await sandboxString(capture, budget, context);
10982
+ index = end;
10983
+ continue;
10984
+ } else if (token >= "0" && token <= "9") {
10985
+ let captureIndex = Number(token);
10986
+ const nextDigit = replacement.charAt(index + 2);
10987
+ if (nextDigit >= "0" && nextDigit <= "9") {
10988
+ const twoDigitIndex = Number(token + nextDigit);
10989
+ if (twoDigitIndex > 0 && twoDigitIndex <= captures.length) {
10990
+ captureIndex = twoDigitIndex;
10991
+ index += 1;
10992
+ }
10993
+ }
10994
+ if (captureIndex === 0 || captureIndex > captures.length) {
10995
+ result += "$";
10996
+ continue;
10997
+ }
10998
+ result += captures[captureIndex - 1] ?? "";
10999
+ } else {
10884
11000
  result += "$";
10885
11001
  continue;
10886
11002
  }
10887
- result += captures[captureIndex - 1] ?? "";
10888
- } else {
10889
- result += "$";
10890
- continue;
11003
+ index += 1;
10891
11004
  }
10892
- index += 1;
11005
+ return budget.allocateString(result);
11006
+ } finally {
11007
+ release();
10893
11008
  }
10894
- return result;
10895
11009
  }
10896
- async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure) {
11010
+ async function replaceWithClosure(value, searchValue, replacer, replaceAll, budget, callClosure, context) {
10897
11011
  const offsets = findReplacementOffsets(value, searchValue, replaceAll);
10898
11012
  let result = "";
10899
11013
  let copiedThrough = 0;
10900
- for (const offset of offsets) {
10901
- result += value.slice(copiedThrough, offset);
10902
- result += String(await callClosure(replacer, [searchValue, offset, value]));
10903
- copiedThrough = offset + searchValue.length;
11014
+ const release = retainValues(budget, () => [value, searchValue, replacer, result]);
11015
+ try {
11016
+ for (const offset of offsets) {
11017
+ result += value.slice(copiedThrough, offset);
11018
+ result += await sandboxString(await callClosure(replacer, [searchValue, offset, value]), budget, context);
11019
+ copiedThrough = offset + searchValue.length;
11020
+ }
11021
+ result += value.slice(copiedThrough);
11022
+ return budget.allocateString(result);
11023
+ } finally {
11024
+ release();
10904
11025
  }
10905
- result += value.slice(copiedThrough);
10906
- return budget.allocateString(result);
10907
11026
  }
10908
11027
  function findReplacementOffsets(value, searchValue, replaceAll) {
10909
11028
  const firstOffset = value.indexOf(searchValue);
@@ -36567,4 +36686,4 @@ export {
36567
36686
  FileSnapshotBackend,
36568
36687
  run
36569
36688
  };
36570
- //# sourceMappingURL=chunk-A6KP64IV.js.map
36689
+ //# sourceMappingURL=chunk-Q64VTJKF.js.map