fix(scripts): preserve UTF-16 surrogate pairs in firecrawl truncation (#109561)

* fix(scripts): preserve UTF-16 surrogate pairs in firecrawl truncation

* test(scripts): cover UTF-16-safe firecrawl truncation

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
lzyyzznl
2026-07-21 09:50:03 +08:00
committed by GitHub
parent d4766068b8
commit f267a4f99b
2 changed files with 7 additions and 1 deletions
+3 -1
View File
@@ -1,5 +1,6 @@
// Firecrawl Compare script supports OpenClaw repository automation.
import { pathToFileURL } from "node:url";
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
import { fetchFirecrawlContent } from "../extensions/firecrawl/api.ts";
import { formatErrorMessage } from "../src/infra/errors.ts";
import { extractReadableContent } from "../src/web-fetch/content-extractors.runtime.js";
@@ -32,7 +33,7 @@ function truncate(value: string, max = 180): string {
if (!value) {
return "";
}
return value.length > max ? `${value.slice(0, max)}` : value;
return value.length > max ? `${truncateUtf16Safe(value, max)}` : value;
}
function readBoundedResponseText(
@@ -176,4 +177,5 @@ export const testing = {
FETCH_HTML_MAX_BYTES,
fetchHtml,
readBoundedResponseText,
truncate,
};
+4
View File
@@ -3,6 +3,10 @@ import { describe, expect, it } from "vitest";
import { testing as firecrawlCompareTesting } from "../../scripts/firecrawl-compare.ts";
describe("firecrawl-compare", () => {
it("does not split surrogate pairs when truncating output", () => {
expect(firecrawlCompareTesting.truncate(`ab🤖cd`, 3)).toBe("ab…");
});
it("fetches local HTML under the byte cap", async () => {
const result = await firecrawlCompareTesting.fetchHtml("https://example.test/page", {
fetchImpl: (() =>