Browse Source

fix(comments): preserve undefined guest anonymity in API parsing

Keep guestIsAnonymous undefined when the field is omitted so legacy-client compatibility fallback can trigger. Explicit false remains strict and still requires guest email.

Made-with: Cursor
main
npmrun 3 weeks ago
parent
commit
f059cd0ee2
  1. 15
      server/api/public/comments-create-body.test.ts
  2. 6
      server/api/public/comments-create-body.ts

15
server/api/public/comments-create-body.test.ts

@ -25,6 +25,21 @@ describe("parsePublicPostCreateCommentBody", () => {
body: "hello",
});
});
test("keeps guestIsAnonymous as undefined when field is missing", () => {
const parsed = parsePublicPostCreateCommentBody({
guestDisplayName: "访客C",
guestEmail: undefined,
body: "legacy",
});
expect(parsed).toEqual({
parentId: null,
guestDisplayName: "访客C",
guestEmail: undefined,
guestIsAnonymous: undefined,
body: "legacy",
});
});
});
describe("parseUnlistedCreateCommentBody", () => {

6
server/api/public/comments-create-body.ts

@ -10,7 +10,7 @@ export type ParsedCreateCommentInput = {
parentId: number | null;
guestDisplayName?: string;
guestEmail?: string;
guestIsAnonymous: boolean;
guestIsAnonymous?: boolean;
body: string;
};
@ -22,7 +22,7 @@ export function parsePublicPostCreateCommentBody(body: CreateCommentRequestBody)
parentId: parseParentId(body.parentId),
guestDisplayName: typeof body.guestDisplayName === "string" ? body.guestDisplayName : undefined,
guestEmail: typeof body.guestEmail === "string" ? body.guestEmail : undefined,
guestIsAnonymous: body.guestIsAnonymous === true,
guestIsAnonymous: typeof body.guestIsAnonymous === "boolean" ? body.guestIsAnonymous : undefined,
body: body.body,
};
}
@ -35,7 +35,7 @@ export function parseUnlistedCreateCommentBody(body: CreateCommentRequestBody):
parentId: parseParentId(body.parentId),
guestDisplayName: typeof body.guestDisplayName === "string" ? body.guestDisplayName : undefined,
guestEmail: typeof body.guestEmail === "string" ? body.guestEmail : undefined,
guestIsAnonymous: body.guestIsAnonymous === true,
guestIsAnonymous: typeof body.guestIsAnonymous === "boolean" ? body.guestIsAnonymous : undefined,
body: body.body,
};
}

Loading…
Cancel
Save