Skip to content

Commit 38d1d18

Browse files
committed
test(gateway): cover C1 replacement in config lookup-path log sanitizer
Add a regression asserting that a config path carrying a C1 byte (U+009B CSI) is replaced with '?' by sanitizeLookupPathForLog before it reaches the config.openFile warning log, and that no raw C1 byte survives. Assertion is scoped to the sanitized filename so it is OS-path-prefix independent. Signed-off-by: lsr911 <[email protected]>
1 parent f217516 commit 38d1d18

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/gateway/server-methods/config.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@ describe("config.openFile", () => {
145145
});
146146
});
147147

148+
it("replaces C1 control characters in the logged failed config path", async () => {
149+
// U+009B is the C1 CSI introducer, an alternative ANSI escape prefix (ESC [).
150+
// Assert only on the sanitized filename portion so the check is independent
151+
// of the OS-specific path prefix (e.g. /tmp vs D:\tmp).
152+
const CSI = String.fromCharCode(0x9b);
153+
await withEnvAsync({ OPENCLAW_CONFIG_PATH: `/tmp/cfg${CSI}.json` }, async () => {
154+
mockExecFileError(new Error("open failed"));
155+
156+
const { logGateway } = await invokeConfigOpenFile();
157+
158+
const logged = String(
159+
(logGateway.warn as unknown as { mock: { calls: unknown[][] } }).mock.calls.at(-1)?.[0] ??
160+
"",
161+
);
162+
expect(logged.startsWith("config.openFile failed path=")).toBe(true);
163+
// The raw C1 byte is replaced with "?" before it reaches the warning log.
164+
expect(logged).toContain("cfg?.json");
165+
expect(logged).not.toContain(CSI);
166+
});
167+
});
168+
148169
it("returns actionable headless environment error when xdg-open reports no method available", async () => {
149170
await withEnvAsync({ OPENCLAW_CONFIG_PATH: "/tmp/config.json" }, async () => {
150171
mockExecFileError(new Error("xdg-open: no method available for opening '/tmp/config.json'"));

0 commit comments

Comments
 (0)