fix: cap memory wiki filenames for safe writes · openclaw/openclaw@ebb8bed
steipete
·
2026-05-06
·
via Recent Commits to openclaw:main
File tree
extensions/memory-wiki/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,7 @@ describe("slugifyWikiSegment", () => {
|
41 | 41 | const fileName = createWikiPageFilename(stem); |
42 | 42 | |
43 | 43 | expect(fileName.endsWith(".md")).toBe(true); |
44 | | -expect(Buffer.byteLength(fileName)).toBeLessThanOrEqual(255); |
| 44 | +expect(Buffer.byteLength(`.${fileName}.fallback.tmp`)).toBeLessThanOrEqual(255); |
45 | 45 | expect(createWikiPageFilename(stem)).toBe(fileName); |
46 | 46 | }); |
47 | 47 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,8 @@ const RELATED_BLOCK_PATTERN = new RegExp(
|
109 | 109 | ); |
110 | 110 | const MAX_WIKI_SEGMENT_BYTES = 240; |
111 | 111 | const MAX_WIKI_FILENAME_COMPONENT_BYTES = 255; |
| 112 | +const MAX_WIKI_SAFE_WRITE_FILENAME_COMPONENT_BYTES = |
| 113 | +MAX_WIKI_FILENAME_COMPONENT_BYTES - Buffer.byteLength(".fallback.tmp") - 1; |
112 | 114 | const WIKI_SEGMENT_HASH_BYTES = 12; |
113 | 115 | |
114 | 116 | function truncateUtf8CodePointSafe(value: string, maxBytes: number): string { |
@@ -152,7 +154,7 @@ export function createWikiPageFilename(stem: string, extension = ".md"): string
|
152 | 154 | const normalizedExtension = extension.startsWith(".") ? extension : `.${extension}`; |
153 | 155 | const maxStemBytes = Math.max( |
154 | 156 | 1, |
155 | | -MAX_WIKI_FILENAME_COMPONENT_BYTES - Buffer.byteLength(normalizedExtension), |
| 157 | +MAX_WIKI_SAFE_WRITE_FILENAME_COMPONENT_BYTES - Buffer.byteLength(normalizedExtension), |
156 | 158 | ); |
157 | 159 | return `${capWikiValueWithHash(stem, maxStemBytes, "page")}${normalizedExtension}`; |
158 | 160 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。