poe-code 14.0.53 → 14.0.55
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 +73 -25
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-js/dist/chunks/{chunk-VDFW3EKS.js → chunk-6LFWVA64.js} +71 -26
- package/packages/safe-js/dist/chunks/{chunk-VDFW3EKS.js.map → chunk-6LFWVA64.js.map} +2 -2
- package/packages/safe-js/dist/chunks/{chunk-4XYGVCOQ.js → chunk-G5LQ37D4.js} +2 -2
- package/packages/safe-js/dist/cli.js +2 -2
- package/packages/safe-js/dist/core.js +1 -1
- package/packages/safe-js/dist/index.js +2 -2
- package/packages/safe-js/dist/interp/globals/regex.d.ts +5 -2
- package/packages/safe-js/dist/interp/globals/regex.js +26 -12
- package/packages/safe-js/dist/interp/globals.js +1 -1
- package/packages/safe-js/dist/interp/interpreter.js +1 -1
- package/packages/safe-js/dist/interp/methods/string.d.ts +2 -2
- package/packages/safe-js/dist/interp/methods/string.js +40 -6
- /package/packages/safe-js/dist/chunks/{chunk-4XYGVCOQ.js.map → chunk-G5LQ37D4.js.map} +0 -0
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
validateMigrationSemantics,
|
|
28
28
|
validateSnapshotData,
|
|
29
29
|
validateSnapshotMigration
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-6LFWVA64.js";
|
|
31
31
|
import {
|
|
32
32
|
createFileSystem,
|
|
33
33
|
createNodeFileSystemAdapterRegistry,
|
|
@@ -8245,4 +8245,4 @@ export {
|
|
|
8245
8245
|
parseMcpConfig,
|
|
8246
8246
|
makeMcpModule
|
|
8247
8247
|
};
|
|
8248
|
-
//# sourceMappingURL=chunk-
|
|
8248
|
+
//# sourceMappingURL=chunk-G5LQ37D4.js.map
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
resolveFsConfig,
|
|
23
23
|
splitFrontmatter,
|
|
24
24
|
withBrokenPipeGuard
|
|
25
|
-
} from "./chunks/chunk-
|
|
25
|
+
} from "./chunks/chunk-G5LQ37D4.js";
|
|
26
26
|
import {
|
|
27
27
|
Budget,
|
|
28
28
|
SandboxError,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
replaceErrorStack,
|
|
35
35
|
restore,
|
|
36
36
|
run
|
|
37
|
-
} from "./chunks/chunk-
|
|
37
|
+
} from "./chunks/chunk-6LFWVA64.js";
|
|
38
38
|
import "./chunks/chunk-UXMKEUH3.js";
|
|
39
39
|
import "./chunks/chunk-5DYEOCT5.js";
|
|
40
40
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
runWithSpawnUsageAccumulator,
|
|
27
27
|
splitFrontmatter,
|
|
28
28
|
supportsSpawnMode
|
|
29
|
-
} from "./chunks/chunk-
|
|
29
|
+
} from "./chunks/chunk-G5LQ37D4.js";
|
|
30
30
|
import {
|
|
31
31
|
Budget,
|
|
32
32
|
FileSnapshotBackend,
|
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
registerPendingHostCallPolicy,
|
|
51
51
|
restore,
|
|
52
52
|
run
|
|
53
|
-
} from "./chunks/chunk-
|
|
53
|
+
} from "./chunks/chunk-6LFWVA64.js";
|
|
54
54
|
import "./chunks/chunk-UXMKEUH3.js";
|
|
55
55
|
import "./chunks/chunk-5DYEOCT5.js";
|
|
56
56
|
import "./chunks/chunk-4YIDX44G.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type SandboxClosure } from "../values.js";
|
|
2
|
-
import { type CompileOwner } from "../budget.js";
|
|
3
|
-
export declare function createRegexGlobals(
|
|
2
|
+
import { type Budget, type CompileOwner } from "../budget.js";
|
|
3
|
+
export declare function createRegexGlobals(options: {
|
|
4
|
+
budget: Budget;
|
|
5
|
+
compileOwner?: CompileOwner;
|
|
6
|
+
}): {
|
|
4
7
|
RegExp: SandboxClosure;
|
|
5
8
|
};
|
|
@@ -1,28 +1,42 @@
|
|
|
1
|
-
import { createSandboxClosure, createSandboxRegex, reconcileCompiledValues } from "../values.js";
|
|
1
|
+
import { createSandboxClosure, createSandboxRegex, isSandboxRegex, reconcileCompiledValues } from "../values.js";
|
|
2
2
|
import { CompileScope } from "../regex/compile-guard.js";
|
|
3
3
|
import { SandboxError } from "../budget.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { sandboxString } from "../string-coercion.js";
|
|
5
|
+
export function createRegexGlobals(options) {
|
|
6
|
+
const invoke = (construct) => async (args, context) => {
|
|
7
|
+
const selected = options.compileOwner ?? context?.compilation?.owner;
|
|
7
8
|
if (context?.compilation?.owner !== undefined && selected !== context.compilation.owner) {
|
|
8
9
|
throw new SandboxError("reentry");
|
|
9
10
|
}
|
|
10
|
-
const operation =
|
|
11
|
-
const compilation = context?.compilation
|
|
11
|
+
const operation = options.budget.acquireCompileOwner(false, selected);
|
|
12
|
+
const compilation = context?.compilation?.owner === operation.owner
|
|
13
|
+
? context.compilation : new CompileScope(operation.owner);
|
|
14
|
+
let source = "";
|
|
15
|
+
const retained = {};
|
|
16
|
+
options.budget.setRetainedValues(retained, () => [...args, source]);
|
|
12
17
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
const pattern = args[0];
|
|
19
|
+
const flags = args[1];
|
|
20
|
+
if (!construct && isSandboxRegex(pattern) && flags === undefined)
|
|
21
|
+
return pattern;
|
|
22
|
+
const sourceValue = isSandboxRegex(pattern) ? pattern.source : pattern;
|
|
23
|
+
const flagsValue = isSandboxRegex(pattern) && flags === undefined ? pattern.flags : flags;
|
|
24
|
+
source = sourceValue === undefined ? "" : await sandboxString(sourceValue, options.budget, context);
|
|
25
|
+
const flagText = flagsValue === undefined ? "" : await sandboxString(flagsValue, options.budget, context);
|
|
26
|
+
const regex = createSandboxRegex(source, flagText, 0, compilation);
|
|
27
|
+
if (compilation !== context?.compilation) {
|
|
28
|
+
reconcileCompiledValues(options.budget, [regex], compilation);
|
|
16
29
|
}
|
|
17
30
|
return regex;
|
|
18
31
|
}
|
|
19
32
|
finally {
|
|
20
|
-
|
|
33
|
+
options.budget.setRetainedValues(retained, undefined);
|
|
34
|
+
if (compilation !== context?.compilation)
|
|
21
35
|
compilation.dispose();
|
|
22
|
-
operation
|
|
36
|
+
operation.release();
|
|
23
37
|
}
|
|
24
38
|
};
|
|
25
39
|
return {
|
|
26
|
-
RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call:
|
|
40
|
+
RegExp: createSandboxClosure({ sandbox: true, name: "RegExp", call: invoke(false), construct: invoke(true) })
|
|
27
41
|
};
|
|
28
42
|
}
|
|
@@ -1938,7 +1938,7 @@ async function evaluateStringMethodCall(node, target, methodName, context) {
|
|
|
1938
1938
|
return {
|
|
1939
1939
|
kind: "normal",
|
|
1940
1940
|
hasValue: true,
|
|
1941
|
-
value: await callStringMethod(target, methodName, args.value, context.budget, (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack), context.compilation)
|
|
1941
|
+
value: await callStringMethod(target, methodName, args.value, context.budget, (closure, closureArgs) => invokeSandboxClosure(closure, closureArgs, context, context.callStack), context.compilation, createCoercionContext(context))
|
|
1942
1942
|
};
|
|
1943
1943
|
}
|
|
1944
1944
|
catch (error) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Expression } from "../../parse.js";
|
|
2
2
|
import { Budget } from "../budget.js";
|
|
3
3
|
import { CompileScope } from "../regex/compile-guard.js";
|
|
4
|
-
import { type SandboxClosure, type SandboxValue } from "../values.js";
|
|
4
|
+
import { type SandboxCallContext, type SandboxClosure, type SandboxValue } from "../values.js";
|
|
5
5
|
type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "isWellFormed" | "lastIndexOf" | "localeCompare" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "toWellFormed" | "trim" | "trimEnd" | "trimStart";
|
|
6
6
|
export declare function getStringMember(value: string, property: string | number, budget: Budget): SandboxValue | undefined;
|
|
7
7
|
export declare function isStringMethodName(property: string | number): property is StringMethodName;
|
|
8
8
|
export declare function validateStringMethodArguments(_methodName: StringMethodName, _args: readonly Expression[]): void;
|
|
9
|
-
export declare function callStringMethod(value: string, methodName: StringMethodName, args: readonly SandboxValue[], budget: Budget, callClosure?: (closure: SandboxClosure, args: readonly SandboxValue[]) => Promise<SandboxValue>, parent?: CompileScope): SandboxValue | Promise<SandboxValue>;
|
|
9
|
+
export declare function callStringMethod(value: string, methodName: StringMethodName, args: readonly SandboxValue[], budget: Budget, callClosure?: (closure: SandboxClosure, args: readonly SandboxValue[]) => Promise<SandboxValue>, parent?: CompileScope, context?: SandboxCallContext): SandboxValue | Promise<SandboxValue>;
|
|
10
10
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { invokeBuiltinClosure } from "../builtin-call.js";
|
|
1
2
|
import { CompileScope } from "../regex/compile-guard.js";
|
|
3
|
+
import { sandboxString } from "../string-coercion.js";
|
|
2
4
|
import { createSandboxClosure, createSandboxRegex, deepCopyFromSandbox, isSandboxClosure, isSandboxRegex } from "../values.js";
|
|
3
5
|
import { executeRegex, toMatchArray } from "./regex.js";
|
|
4
6
|
const SPLIT_STRING_MESSAGE = "String#split only supports string separator values.";
|
|
@@ -51,9 +53,21 @@ export function getStringMember(value, property, budget) {
|
|
|
51
53
|
name: `String#${property}`,
|
|
52
54
|
...(property === "localeCompare" ? { length: 1 } : {}),
|
|
53
55
|
...(property === "isWellFormed" || property === "toWellFormed" ? { length: 0 } : {}),
|
|
54
|
-
call: (args, context) =>
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
call: async (args, context) => {
|
|
57
|
+
const receiver = context?.thisValue;
|
|
58
|
+
if (receiver === null || receiver === undefined) {
|
|
59
|
+
throw new TypeError(`String#${property} requires a non-null receiver.`);
|
|
60
|
+
}
|
|
61
|
+
const retainedReceiver = {};
|
|
62
|
+
budget.setRetainedValues(retainedReceiver, () => [receiver]);
|
|
63
|
+
try {
|
|
64
|
+
const string = await sandboxString(receiver, budget, context);
|
|
65
|
+
return await callStringMethod(string, property, args, budget, (closure, closureArgs) => invokeBuiltinClosure(closure, closureArgs, budget, context, undefined), context?.compilation, context);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
budget.setRetainedValues(retainedReceiver, undefined);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
73
|
function getStringIndex(property) {
|
|
@@ -67,7 +81,7 @@ export function isStringMethodName(property) {
|
|
|
67
81
|
return typeof property === "string" && stringMethodNames.has(property);
|
|
68
82
|
}
|
|
69
83
|
export function validateStringMethodArguments(_methodName, _args) { }
|
|
70
|
-
export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
|
|
84
|
+
export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent, context) {
|
|
71
85
|
if (methodName === "isWellFormed") {
|
|
72
86
|
for (let index = 0; index < value.length; index++) {
|
|
73
87
|
const codeUnit = value.charCodeAt(index);
|
|
@@ -108,6 +122,9 @@ export function callStringMethod(value, methodName, args, budget, callClosure =
|
|
|
108
122
|
if (methodName === "replace" || methodName === "replaceAll") {
|
|
109
123
|
return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
|
|
110
124
|
}
|
|
125
|
+
if ((methodName === "match" || methodName === "matchAll" || methodName === "search") && !isSandboxRegex(args[0])) {
|
|
126
|
+
return callStringPattern(value, methodName, args[0], budget, parent, context);
|
|
127
|
+
}
|
|
111
128
|
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
112
129
|
const compilation = new CompileScope(operation.owner);
|
|
113
130
|
try {
|
|
@@ -365,6 +382,22 @@ function callSplit(value, args, budget, compilation) {
|
|
|
365
382
|
budget.allocateArrayLength(result.length);
|
|
366
383
|
return result;
|
|
367
384
|
}
|
|
385
|
+
async function callStringPattern(value, methodName, pattern, budget, parent, context) {
|
|
386
|
+
const operation = budget.acquireCompileOwner(false, parent?.owner);
|
|
387
|
+
const compilation = new CompileScope(operation.owner);
|
|
388
|
+
const retainedPattern = {};
|
|
389
|
+
budget.setRetainedValues(retainedPattern, () => [pattern]);
|
|
390
|
+
try {
|
|
391
|
+
const source = pattern === undefined ? "" : await sandboxString(pattern, budget, context);
|
|
392
|
+
const regex = createSandboxRegex(source, methodName === "matchAll" ? "g" : "", 0, compilation);
|
|
393
|
+
return callMatchLikeMethod(value, methodName, [regex], compilation);
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
budget.setRetainedValues(retainedPattern, undefined);
|
|
397
|
+
compilation.dispose();
|
|
398
|
+
operation.release();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
368
401
|
function callMatchLikeMethod(value, methodName, args, compilation) {
|
|
369
402
|
const regex = args[0];
|
|
370
403
|
if (!isSandboxRegex(regex))
|
|
@@ -387,19 +420,20 @@ function callMatchLikeMethod(value, methodName, args, compilation) {
|
|
|
387
420
|
const matcher = methodName === "matchAll"
|
|
388
421
|
? createSandboxRegex(regex.source, regex.flags, regex.lastIndex, compilation)
|
|
389
422
|
: regex;
|
|
390
|
-
const matches = collectRegexMatches(matcher, value, true);
|
|
423
|
+
const matches = collectRegexMatches(matcher, value, true, compilation.owner?.budget);
|
|
391
424
|
if (methodName === "match" && matches.length === 0)
|
|
392
425
|
return null;
|
|
393
426
|
return methodName === "match"
|
|
394
427
|
? matches.map((match) => match.text)
|
|
395
428
|
: matches.map((match) => toMatchArray(match, value));
|
|
396
429
|
}
|
|
397
|
-
function collectRegexMatches(regex, value, all) {
|
|
430
|
+
function collectRegexMatches(regex, value, all, budget) {
|
|
398
431
|
const matches = [];
|
|
399
432
|
do {
|
|
400
433
|
const match = executeRegex(regex, value);
|
|
401
434
|
if (match === null)
|
|
402
435
|
break;
|
|
436
|
+
budget?.allocateArrayLength(matches.length + 1);
|
|
403
437
|
matches.push(match);
|
|
404
438
|
if (all && match.text.length === 0)
|
|
405
439
|
regex.lastIndex += 1;
|
|
File without changes
|