fix(housekeeping): count preference payload bytes

This commit is contained in:
Simo committed 2026-08-27 17:53:16 +02:00
1 parent 4e0bf598ed
commit 60968409aa
3 files changed
+28 -2

No files matched your search

@@ -71,4 +71,21 @@ describe("housekeeping preferences schema", () => {
}).success,
).toBe(false);
});
it("rejects a Unicode payload whose UTF-8 bytes exceed the 4096-byte limit", () => {
const value = {
...defaultHousekeepingPreferences(),
pinnedRouteIds: Array.from(
{ length: 29 },
(_, index) => `${index.toString().padStart(3, "0")}${"é".repeat(125)}`,
),
};
const serialized = JSON.stringify(value);
expect(serialized.length).toBeLessThanOrEqual(4096);
expect(new TextEncoder().encode(serialized).byteLength).toBeGreaterThan(
4096,
);
expect(housekeepingPreferencesSchema.safeParse(value).success).toBe(false);
});
});
@@ -45,7 +45,7 @@ export const housekeepingPreferencesSchema: z.ZodType<HousekeepingPreferences> =
.strict()
.superRefine((preferences, context) => {
if (
JSON.stringify(preferences).length >
new TextEncoder().encode(JSON.stringify(preferences)).byteLength >
HOUSEKEEPING_PREFERENCE_MAX_SERIALIZED_BYTES
) {
context.addIssue({