Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pm-stack/aggregator/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,13 @@ export interface SubscriptionSanitization {
/** One subscription row safe to hand to the renderers (#2446): the
* strip maps esc(s.name)/esc(s.plan) and reads renewsAt unguarded, so
* a null row or a non-string field 500s /quota and is served verbatim
* by /api/quota.json. */
* by /api/quota.json. renewsAt must be null or a real ISO calendar
* date (#3513): invalid strings survive sanitization otherwise and
* render verbatim as renewal dates. */
export function isSubscriptionRow(v: unknown): v is { name: string; plan: string; renewsAt: string | null } {
if (!isRecord(v)) return false;
return (
typeof v.name === "string" && typeof v.plan === "string" && (typeof v.renewsAt === "string" || v.renewsAt === null)
typeof v.name === "string" && typeof v.plan === "string" && (v.renewsAt === null || isIsoDate(v.renewsAt))
);
}

Expand Down
15 changes: 15 additions & 0 deletions pm-stack/aggregator/test/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ describe("feed subscriptions sanitization (#2446)", () => {
expect(out.dropped).toBe(1);
});

test("invalid renewsAt strings drop; ISO dates and null survive (#3513)", async () => {
const bad = (renewsAt: string) => ({ name: "Bad", plan: "p", renewsAt });
const out = sanitizeSubscriptions([
SUB,
SUB_NULL_RENEW,
bad("banana"),
bad("2026-02-30"),
bad("2026-13-01"),
bad("12/01/2026"),
bad("2026-12-01banana"),
]);
expect(out.rows).toEqual([SUB, SUB_NULL_RENEW]);
expect(out.dropped).toBe(5);
});

test("a mixed valid/invalid array through loadFeed keeps only renderer-safe rows", async () => {
const loaded = await loadWithSubs([SUB, null, "junk", { name: "Ok", plan: 7, renewsAt: null }, SUB_NULL_RENEW]);
expect(loaded?.subscriptions).toEqual([SUB, SUB_NULL_RENEW]);
Expand Down
Loading