



























@@ -7,7 +7,7 @@ import { mkdir, mkdtemp, rm } from "node:fs/promises";
77import os from "node:os";
88import path from "node:path";
99import { afterEach, describe, expect, it, vi } from "vitest";
10-import { readEnvInt, resolveSandboxWorkdir } from "./bash-tools.shared.js";
10+import { deriveSessionName, readEnvInt, resolveSandboxWorkdir } from "./bash-tools.shared.js";
11111212async function withTempDir(run: (dir: string) => Promise<void>) {
1313const dir = await mkdtemp(path.join(os.tmpdir(), "openclaw-bash-workdir-"));
@@ -118,3 +118,29 @@ describe("resolveSandboxWorkdir", () => {
118118});
119119});
120120});
121+122+describe("deriveSessionName", () => {
123+it("labels well-formed quoted commands", () => {
124+expect(deriveSessionName('node "my server.js" --port 8080')).toBe("node my server.js");
125+expect(deriveSessionName("git commit -m 'fix bug'")).toBe("git commit");
126+});
127+128+it("keeps grouping backslash-bearing quoted spans into one token", () => {
129+expect(deriveSessionName('tar "a\\b c"')).toBe("tar a\\b c");
130+});
131+132+it("treats backslash as literal inside single-quoted spans", () => {
133+expect(deriveSessionName("cmd 'a b\\' next")).toBe("cmd a b\\");
134+});
135+136+it("returns a label without catastrophic backtracking on unterminated quoted backslash runs", () => {
137+for (const quote of [`"`, `'`]) {
138+const malicious = `node ${quote}${"\\".repeat(50000)}`;
139+const start = process.hrtime.bigint();
140+const label = deriveSessionName(malicious);
141+const elapsedMs = Number(process.hrtime.bigint() - start) / 1e6;
142+expect(typeof label).toBe("string");
143+expect(elapsedMs).toBeLessThan(100);
144+}
145+});
146+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。