Repository navigation
fix: trim whitespace from contact variable fallbacks - #457
sarmah-rup wants to merge 1 commit into
Conversation
|
@sarmah-rup is attempting to deploy a commit to the kmkoushik's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughFallback values in contact variable replacements are trimmed before substitution. When no fallback is provided, the replacement remains an empty string. A unit test covers a whitespace-padded fallback. Priority: ⬇️ Low Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The change is limited to trimming absent-contact fallbacks, with a regression test for padded input. No material merge risk was identified. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
apps/web/src/server/utils/contact-variable-replacement.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. apps/web/src/server/utils/contact-variable-replacement.unit.test.tsESLint skipped: the matched ESLint configuration already failed (missing-dependency). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bug
A contact variable with a padded fallback keeps the padding. With an empty
firstName,Hi {{ firstName, fallback= there }}, welcome!renders asHi there , welcome!, with a stray space before and after the fallback. The same helper renders campaign subjects, API-created campaign HTML and double opt-in subjects.Root cause
CONTACT_VARIABLE_REGEXcaptures the fallback withfallback=([^}]+), followed by\s*\}\}. The greedy capture eats the spaces before}}(and any after=), so the trailing\s*matches nothing, andreplaceContactVariablesreturns the raw capture.Solution
Trim the fallback before returning it. Variable names were already whitespace-tolerant through the regex, and unpadded fallbacks (
{{firstName,fallback=there}}, the form in the docs) render the same as before.Closes #456
Testing
contact-variable-replacement.unit.test.ts. It fails onmainwithexpected 'Hi there , welcome!' to be 'Hi there, welcome!'and passes with the fix.pnpm test:unitinapps/web: 21 files, 127 tests pass.pnpm test: 31 files, 157 tests pass.Summary by cubic
Fixes contact variable fallbacks keeping whitespace padding, so
Hi {{ firstName, fallback= there }}, welcome!renders asHi there, welcome!without stray spaces.Bug Fixes
{{firstName,fallback=there}}are unaffected.mainand passes with the fix.Written for commit f1332ef. Summary will update on new commits.
Summary by CodeRabbit