mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:20:43 +00:00
fix: cap memory wiki filenames for safe writes
This commit is contained in:
@@ -41,7 +41,7 @@ describe("slugifyWikiSegment", () => {
|
||||
const fileName = createWikiPageFilename(stem);
|
||||
|
||||
expect(fileName.endsWith(".md")).toBe(true);
|
||||
expect(Buffer.byteLength(fileName)).toBeLessThanOrEqual(255);
|
||||
expect(Buffer.byteLength(`.${fileName}.fallback.tmp`)).toBeLessThanOrEqual(255);
|
||||
expect(createWikiPageFilename(stem)).toBe(fileName);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,6 +109,8 @@ const RELATED_BLOCK_PATTERN = new RegExp(
|
||||
);
|
||||
const MAX_WIKI_SEGMENT_BYTES = 240;
|
||||
const MAX_WIKI_FILENAME_COMPONENT_BYTES = 255;
|
||||
const MAX_WIKI_SAFE_WRITE_FILENAME_COMPONENT_BYTES =
|
||||
MAX_WIKI_FILENAME_COMPONENT_BYTES - Buffer.byteLength(".fallback.tmp") - 1;
|
||||
const WIKI_SEGMENT_HASH_BYTES = 12;
|
||||
|
||||
function truncateUtf8CodePointSafe(value: string, maxBytes: number): string {
|
||||
@@ -152,7 +154,7 @@ export function createWikiPageFilename(stem: string, extension = ".md"): string
|
||||
const normalizedExtension = extension.startsWith(".") ? extension : `.${extension}`;
|
||||
const maxStemBytes = Math.max(
|
||||
1,
|
||||
MAX_WIKI_FILENAME_COMPONENT_BYTES - Buffer.byteLength(normalizedExtension),
|
||||
MAX_WIKI_SAFE_WRITE_FILENAME_COMPONENT_BYTES - Buffer.byteLength(normalizedExtension),
|
||||
);
|
||||
return `${capWikiValueWithHash(stem, maxStemBytes, "page")}${normalizedExtension}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user