mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
9a2aff2bea
JSON.parse keeps only the last value for a repeated name, so an ASAR header that declared a path twice listed one member, hid the other and still reported complete coverage. Add findDuplicateJsonMember, an iterative scan of validated JSON text that does not recurse, so the deeply nested headers REA already admits stay readable. readAsarHeader now refuses a repeated member name as a malformed index, the same way the listing refuses unsafe path components.
30 lines
959 B
TypeScript
30 lines
959 B
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { findDuplicateJsonMember } from "./jsonDuplicateMember.js";
|
|
|
|
it.each([
|
|
['{"a":1,"a":2}', { name: "a", offset: 7 }],
|
|
['{"x":{"a":1,"b":{"a":2},"a":3}}', { name: "a", offset: 24 }],
|
|
['{"a":1,"\\u0061":2}', { name: "a", offset: 7 }],
|
|
['[{"k":"k"},{"k":["k","k"],"k":0}]', { name: "k", offset: 26 }],
|
|
])("finds the repeated name in %s", (text, expected) => {
|
|
expect(findDuplicateJsonMember(text)).toEqual(expected);
|
|
});
|
|
|
|
it.each([
|
|
'{"a":"a","b":"a"}',
|
|
'{"a":{"a":{"a":1}}}',
|
|
'["a","a",{"a":1},{"a":2}]',
|
|
'{"a\\"b":1,"a":2,"b":"\\\\"}',
|
|
'"a"',
|
|
"{}",
|
|
])("accepts distinct names in %s", (text) => {
|
|
expect(findDuplicateJsonMember(text)).toBeUndefined();
|
|
});
|
|
|
|
it("scans nesting deeper than the call stack allows", () => {
|
|
const depth = 200_000;
|
|
const text = `${'{"d":'.repeat(depth)}{"a":1,"a":2}${"}".repeat(depth)}`;
|
|
expect(findDuplicateJsonMember(text)).toMatchObject({ name: "a" });
|
|
});
|