fix(cli): reject invalid UTF-8 JSON file bytes (#613)

* fix(cli): reject invalid UTF-8 JSON file bytes

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* test(browser): preserve unknown with-scope loader bindings

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

---------

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 02:10:11 +08:00
committed by GitHub
parent 1bd641d39f
commit 22acb0d5d7
3 changed files with 57 additions and 4 deletions
+5 -1
View File
@@ -17,7 +17,11 @@ export const readJsonFile = async (
const encoded = await readFile(canonicalPath);
let decoded: unknown;
try {
decoded = JSON.parse(encoded.toString("utf8"));
decoded = JSON.parse(
new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(
encoded,
),
);
} catch (cause: unknown) {
return err(new EvidenceFileError("read", "invalid-json", { cause }));
}