fix(snapshot): classify non-object roots as invalid content (#2685)

Co-authored-by: jiangjiang248 <237556902+jiangjiang248@users.noreply.github.com>
This commit is contained in:
jiangjiang248
2026-10-13 16:04:44 +08:00
committed by GitHub
co-authored by jiangjiang248
parent c923fb0dc9
commit 9cf49c7a78
2 changed files with 94 additions and 2 deletions
+6 -2
View File
@@ -78,7 +78,9 @@ export const readJsonObjectFile = (
value === null ||
Array.isArray(value)
)
throw new TypeError("JSON document root must be an object");
return err(
invalidJson(operation, "JSON document root must be an object"),
);
for (const members of scans)
for (const [key, member] of members) {
if (!Object.hasOwn(value, key)) continue;
@@ -177,7 +179,9 @@ export const readJsonObjectFile = (
signal === undefined ? {} : { signal },
);
if (!rootObject)
throw new TypeError("JSON document root must be an object");
return err(
invalidJson(operation, "JSON document root must be an object"),
);
const digest = hash.digest("hex");
if (previousDigest !== undefined && digest !== previousDigest)
throw new RegularFileChangedError(path);