Skip to content

Scheduling infrastructure for absolutely everyone.

fix(CalEventParser): skip null/undefined values in getUserFieldsResponses (#29703)

okxint009f91d16365
diff --git a/packages/lib/CalEventParser.test.ts b/packages/lib/CalEventParser.test.ts
index 716584b71b9..bf6a50f4821 100644
--- a/packages/lib/CalEventParser.test.ts
+++ b/packages/lib/CalEventParser.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest";
import type { CalendarEvent } from "@calcom/types/Calendar";
-import { getRichDescription } from "./CalEventParser";
+import { getRichDescription, getUserFieldsResponses } from "./CalEventParser";
describe("getRichDescription", () => {
const t = ((key: string, _args?: Record<string, unknown>) => key) as TFunction;
@@ -85,3 +85,32 @@ describe("getRichDescription", () => {
expect(description).toContain("who:");
});
});
+
+describe("getUserFieldsResponses", () => {
+ const t = ((key: string) => key) as TFunction;
+
+ it("does not render null values for unanswered optional booking questions", () => {
+ // When an optional booking question is left unanswered, customInputs may store null
+ // for that field. Before the fix, null coerced to the string "null" in the template
+ // literal, polluting the calendar event description.
+ const result = getUserFieldsResponses(
+ { customInputs: { "Phone Number": null, Name: "Alice" } },
+ t
+ );
+
+ expect(result).not.toContain("null");
+ expect(result).toContain("Name");
+ expect(result).toContain("Alice");
+ });
+
+ it("does not render empty string values for booking questions", () => {
+ const result = getUserFieldsResponses(
+ { customInputs: { "Phone Number": "", Name: "Bob" } },
+ t
+ );
+
+ expect(result).not.toContain("Phone Number");
+ expect(result).toContain("Name");
+ expect(result).toContain("Bob");
+ });
+});
diff --git a/packages/lib/CalEventParser.ts b/packages/lib/CalEventParser.ts
index ae05ca01c33..c7388c3639a 100644
--- a/packages/lib/CalEventParser.ts
+++ b/packages/lib/CalEventParser.ts
@@ -117,7 +117,7 @@ export const getUserFieldsResponses = (
const responsesString = Object.keys(labelValueMap)
.map((key) => {
if (!labelValueMap) return "";
- if (labelValueMap[key] !== "") {
+ if (labelValueMap[key] != null && labelValueMap[key] !== "") {
return `
${t(key)}:
${labelValueMap[key]}