mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 02:04:34 +00:00
test(perf): simplify temp-path guard scan loop
This commit is contained in:
@@ -12,6 +12,8 @@ type QuoteScanState = {
|
|||||||
};
|
};
|
||||||
const WEAK_RANDOM_SAME_LINE_PATTERN =
|
const WEAK_RANDOM_SAME_LINE_PATTERN =
|
||||||
/(?:Date\.now[^\r\n]*Math\.random|Math\.random[^\r\n]*Date\.now)/u;
|
/(?:Date\.now[^\r\n]*Math\.random|Math\.random[^\r\n]*Date\.now)/u;
|
||||||
|
const PATH_JOIN_CALL_PATTERN = /path\s*\.\s*join\s*\(/u;
|
||||||
|
const OS_TMPDIR_CALL_PATTERN = /os\s*\.\s*tmpdir\s*\(/u;
|
||||||
|
|
||||||
function shouldSkip(relativePath: string): boolean {
|
function shouldSkip(relativePath: string): boolean {
|
||||||
return shouldSkipGuardrailRuntimeSource(relativePath);
|
return shouldSkipGuardrailRuntimeSource(relativePath);
|
||||||
@@ -144,10 +146,12 @@ function isOsTmpdirExpression(argument: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mightContainDynamicTmpdirJoin(source: string): boolean {
|
function mightContainDynamicTmpdirJoin(source: string): boolean {
|
||||||
|
if (!source.includes("path") || !source.includes("join") || !source.includes("tmpdir")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
source.includes("path") &&
|
(source.includes("path.join") || PATH_JOIN_CALL_PATTERN.test(source)) &&
|
||||||
source.includes("path.join") &&
|
(source.includes("os.tmpdir") || OS_TMPDIR_CALL_PATTERN.test(source)) &&
|
||||||
source.includes("os.tmpdir") &&
|
|
||||||
source.includes("`") &&
|
source.includes("`") &&
|
||||||
source.includes("${")
|
source.includes("${")
|
||||||
);
|
);
|
||||||
@@ -220,9 +224,6 @@ describe("temp path guard", () => {
|
|||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const relativePath = file.relativePath;
|
const relativePath = file.relativePath;
|
||||||
if (shouldSkip(relativePath)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (hasDynamicTmpdirJoin(file.source)) {
|
if (hasDynamicTmpdirJoin(file.source)) {
|
||||||
offenders.push(relativePath);
|
offenders.push(relativePath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user