Skip to content

馃悶 - Whitespace inside {{var, fallback=...}} ends up in the rendered text聽#456

Description

@sarmah-rup

What happened?

Whitespace inside a contact variable with a fallback ends up in the rendered text. With an empty firstName, the subject Hi {{ firstName, fallback= there }}, welcome! renders as Hi there , welcome!, with an extra space on each side of the fallback. {{firstName,fallback=there}} without padding renders fine.

In apps/web/src/server/utils/contact-variable-replacement.ts, CONTACT_VARIABLE_REGEX captures the fallback with fallback=([^}]+). That group swallows any spaces before }} (and after =), and replaceContactVariables returns the capture as it is. The regex already allows whitespace around the variable name and the comma, so padding inside the braces looks like it's meant to work. This helper renders campaign subjects, API-created campaign HTML and double opt-in subjects.

Replication Steps

replaceContactVariables(
  'Hi {{ firstName, fallback= there }}, welcome!',
  { ...contact, firstName: null },
  [],
)
// 'Hi  there , welcome!'   expected 'Hi there, welcome!'

Self hosted or Cloud?

Found in the code on main; not specific to either.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions