Skip to content

Commit 009f91d

Browse files
authored
fix(CalEventParser): skip null/undefined values in getUserFieldsResponses (calcom#29703)
When a booking question is optional and left unanswered, the field value stored in customInputs can be null. The previous guard only checked for empty strings, so null (and undefined) would coerce to the literal strings "null"/"undefined" inside the template literal, polluting calendar event descriptions. Fixes calcom#29688
1 parent bb7c87c commit 009f91d

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

packages/lib/CalEventParser.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
33

44
import type { CalendarEvent } from "@calcom/types/Calendar";
55

6-
import { getRichDescription } from "./CalEventParser";
6+
import { getRichDescription, getUserFieldsResponses } from "./CalEventParser";
77

88
describe("getRichDescription", () => {
99
const t = ((key: string, _args?: Record<string, unknown>) => key) as TFunction;
@@ -85,3 +85,32 @@ describe("getRichDescription", () => {
8585
expect(description).toContain("who:");
8686
});
8787
});
88+
89+
describe("getUserFieldsResponses", () => {
90+
const t = ((key: string) => key) as TFunction;
91+
92+
it("does not render null values for unanswered optional booking questions", () => {
93+
// When an optional booking question is left unanswered, customInputs may store null
94+
// for that field. Before the fix, null coerced to the string "null" in the template
95+
// literal, polluting the calendar event description.
96+
const result = getUserFieldsResponses(
97+
{ customInputs: { "Phone Number": null, Name: "Alice" } },
98+
t
99+
);
100+
101+
expect(result).not.toContain("null");
102+
expect(result).toContain("Name");
103+
expect(result).toContain("Alice");
104+
});
105+
106+
it("does not render empty string values for booking questions", () => {
107+
const result = getUserFieldsResponses(
108+
{ customInputs: { "Phone Number": "", Name: "Bob" } },
109+
t
110+
);
111+
112+
expect(result).not.toContain("Phone Number");
113+
expect(result).toContain("Name");
114+
expect(result).toContain("Bob");
115+
});
116+
});

packages/lib/CalEventParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const getUserFieldsResponses = (
117117
const responsesString = Object.keys(labelValueMap)
118118
.map((key) => {
119119
if (!labelValueMap) return "";
120-
if (labelValueMap[key] !== "") {
120+
if (labelValueMap[key] != null && labelValueMap[key] !== "") {
121121
return `
122122
${t(key)}:
123123
${labelValueMap[key]}

0 commit comments

Comments
 (0)