mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-30 20:53:34 +00:00
fix(plugin-sdk): guard legacy dedupe JSON parse against malformed files (#98125)
This commit is contained in:
@@ -232,6 +232,20 @@ describe("createPersistentDedupe", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("treats malformed legacy JSON cache files as empty", async () => {
|
||||
const root = await createTempDir("openclaw-legacy-dedupe-malformed-");
|
||||
const legacyPath = path.join(root, "legacy.json");
|
||||
await fs.writeFile(legacyPath, "{not valid json");
|
||||
|
||||
await expect(
|
||||
listPersistentDedupeLegacyJsonFileEntries({
|
||||
filePath: legacyPath,
|
||||
ttlMs: 500,
|
||||
now: 1_100,
|
||||
}),
|
||||
).resolves.toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("warms empty namespaces and ignores retired JSON cache files", async () => {
|
||||
const root = await createTempDir("openclaw-dedupe-");
|
||||
const emptyReader = createDedupe(root, { ttlMs: 10_000 });
|
||||
|
||||
@@ -326,7 +326,12 @@ function parseLegacyDedupeData(raw: string): {
|
||||
data: Record<string, number>;
|
||||
invalidCount: number;
|
||||
} {
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(raw) as unknown;
|
||||
} catch {
|
||||
return { data: {}, invalidCount: 0 };
|
||||
}
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return { data: {}, invalidCount: 0 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user