Skip to content

Commit eb4c2af

Browse files
committed
fix(config): preserve Unicode in validation received values
1 parent 0e9db60 commit eb4c2af

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/config/issue-location.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ describe("appendReceivedValueHint", () => {
249249
).toBe('Invalid input (allowed: "minimal", "coding"), got: "none"');
250250
});
251251

252+
it("keeps truncated received values on a valid UTF-16 boundary", () => {
253+
const message = appendReceivedValueHint(
254+
"invalid input",
255+
"gateway.bind",
256+
`${"x".repeat(155)}🎉tail`,
257+
);
258+
expect(message).not.toMatch(
259+
/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u,
260+
);
261+
});
262+
252263
it("skips when message already mentions received", () => {
253264
expect(appendReceivedValueHint("expected string, received number", "gateway.port", 18789)).toBe(
254265
"expected string, received number",

src/config/issue-location.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from "node:path";
2+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
23
import JSON5 from "json5";
34
import { isSensitiveConfigPath } from "./sensitive-paths.js";
45
import type { ConfigValidationIssue } from "./types.js";
@@ -255,7 +256,7 @@ function stringifyReceivedValue(value: unknown): string | null {
255256
if (serialized === undefined) {
256257
return null;
257258
}
258-
return serialized.length > 160 ? `${serialized.slice(0, 157)}...` : serialized;
259+
return serialized.length > 160 ? `${truncateUtf16Safe(serialized, 157)}...` : serialized;
259260
} catch {
260261
return null;
261262
}

0 commit comments

Comments
 (0)