mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 23:20:22 +00:00
fix(node-host): decode Windows exec output with active code page (openclaw#30652) thanks @Sid-Qin
Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { withEnv } from "../test-utils/env.js";
|
||||
import { sanitizeEnv } from "./invoke.js";
|
||||
import { decodeCapturedOutputBuffer, parseWindowsCodePage, sanitizeEnv } from "./invoke.js";
|
||||
import { buildNodeInvokeResultParams } from "./runner.js";
|
||||
|
||||
describe("node-host sanitizeEnv", () => {
|
||||
@@ -53,6 +53,36 @@ describe("node-host sanitizeEnv", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("node-host output decoding", () => {
|
||||
it("parses code pages from chcp output text", () => {
|
||||
expect(parseWindowsCodePage("Active code page: 936")).toBe(936);
|
||||
expect(parseWindowsCodePage("活动代码页: 65001")).toBe(65001);
|
||||
expect(parseWindowsCodePage("no code page")).toBeNull();
|
||||
});
|
||||
|
||||
it("decodes GBK output on Windows when code page is known", () => {
|
||||
let supportsGbk = true;
|
||||
try {
|
||||
void new TextDecoder("gbk");
|
||||
} catch {
|
||||
supportsGbk = false;
|
||||
}
|
||||
|
||||
const raw = Buffer.from([0xb2, 0xe2, 0xca, 0xd4, 0xa1, 0xab, 0xa3, 0xbb]);
|
||||
const decoded = decodeCapturedOutputBuffer({
|
||||
buffer: raw,
|
||||
platform: "win32",
|
||||
windowsEncoding: "gbk",
|
||||
});
|
||||
|
||||
if (!supportsGbk) {
|
||||
expect(decoded).toContain("<22>");
|
||||
return;
|
||||
}
|
||||
expect(decoded).toBe("测试~;");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildNodeInvokeResultParams", () => {
|
||||
it("omits optional fields when null/undefined", () => {
|
||||
const params = buildNodeInvokeResultParams(
|
||||
|
||||
Reference in New Issue
Block a user