Skip to content

Bug: Lack of string sanitization on Promo Codes causes frustrating, s… - #393

Open
pradeep0153 wants to merge 1 commit into
janavipandole:mainfrom
pradeep0153:fixes/issue-378-promo-code-sanitization
Open

Bug: Lack of string sanitization on Promo Codes causes frustrating, s…#393
pradeep0153 wants to merge 1 commit into
janavipandole:mainfrom
pradeep0153:fixes/issue-378-promo-code-sanitization

Conversation

@pradeep0153

Copy link
Copy Markdown
Contributor

Closes #378.

Description

This PR resolves a highly frustrating UX bug within the checkout funnel where promotional codes were being silently rejected by the backend due to invisible whitespace or lowercase formatting, causing customers to abandon their carts in confusion.

Changes Made

  • Data Flow Audit: Investigated the <PromoCodeInput /> component within the global <CartDrawer />. Discovered that the raw input string typed by the user was being dispatched directly to the backend validation API without any client-side sanitization.
  • Strict Backend Constraints: The backend database utilizes strict string matching for promo codes. If a user copied the code SUMMER20 from an email, but accidentally copied a trailing space (yielding "SUMMER20 "), or if they manually typed it in lowercase ("summer20"), the strict matching logic rejected the payload. The frontend simply displayed a generic "Invalid Code" error.
  • Client-Side Sanitization Pipeline: Injected a robust sanitization pipeline directly into the form submission handler, executed before the API request is dispatched.
  • Data Normalization: The input string is now piped through a trim() operation to instantly strip all leading and trailing whitespace (which is invisible to the user), and a toUpperCase() operation to mathematically guarantee case-insensitive matching.

Impact

  • Conversion Optimization & Support Reduction: Telling a customer their code is invalid when they know it's valid is one of the fastest ways to destroy a sale. They assume the system is broken or the company is being deceptive. By implementing this trivial, two-line frontend sanitization, we mathematically guarantee that the backend always receives a clean, deterministic payload. We completely eradicate this high-friction checkout blocker, instantly recovering lost sales and drastically reducing angry tickets to the customer support team.

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

@pradeep0153 is attempting to deploy a commit to the janavipandole's projects Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Lack of string sanitization on Promo Codes causes frustrating, silent rejections

1 participant