Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/web/src/server/utils/contact-variable-replacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export function replaceContactVariables(
return contactValue;
}

return fallback ?? "";
// The regex lets whitespace before `}}` fall into the fallback capture
return fallback?.trim() ?? "";
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ describe("replaceContactVariables", () => {
).toBe("Welcome, you!");
});

it("does not keep whitespace padding in the fallback value", () => {
const contact = {
...baseContact,
firstName: null,
} satisfies Contact;

expect(
replaceContactVariables(
"Hi {{ firstName, fallback= there }}, welcome!",
contact,
[...BUILT_IN_CONTACT_VARIABLES],
),
).toBe("Hi there, welcome!");
});

it("uses fallback values for nullable built-in variables", () => {
const contact = {
...baseContact,
Expand Down