Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(shared): refuse surrogate code points in htmlVisibleText
lhy-dcf9cdf2c2d12fd
diff --git a/shared/app.test.ts b/shared/app.test.tsindex 6da3262e83..d42d7cfed0 100644--- a/shared/app.test.ts+++ b/shared/app.test.ts@@ -109,3 +109,14 @@ describe("appDoneOf", () => {expect(appDoneOf("Run", { content: [] }, 1)).toEqual({ tool: "Run", at: 1 });});});+++describe("htmlVisibleText numeric character references", () => {+ it("leaves surrogate code points as written, like other unrepresentable code points", () => {+ expect(htmlVisibleText("�")).toBe("�");+ expect(htmlVisibleText("�")).toBe("�");+ expect(htmlVisibleText("�")).toBe("�");+ expect(htmlVisibleText("�")).toBe("�");+ expect(htmlVisibleText("😀")).toBe("😀");+ });+});diff --git a/shared/app.ts b/shared/app.tsindex 8c7f2147d2..b16e4c0a5c 100644--- a/shared/app.ts+++ b/shared/app.ts@@ -358,7 +358,7 @@ export function htmlVisibleText(html: string): string {const lower = name.toLowerCase();if (ENTITIES[lower] !== undefined) return ENTITIES[lower]!;const code = lower.startsWith("#x") ? Number.parseInt(lower.slice(2), 16) : lower.startsWith("#") ? Number.parseInt(lower.slice(1), 10) : NaN;- return Number.isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : whole;+ return Number.isFinite(code) && code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff) ? String.fromCodePoint(code) : whole;}).replace(/\s+/g, " ").trim();