mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
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:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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: (() =>
|
||||
|
||||
Reference in New Issue
Block a user