Skip to content

Case‑sensitivity issue in CouponValidator #2252

@JakubTeczar

Description

@JakubTeczar

Lunar version: 1.0.0‑beta.24
Laravel Version: 11.45.1
PHP Version: 8.2.28
Database Driver & Version: MySQL 8

Expected Behaviour:

Coupon codes should be either case‑insensitive or explicitly enforced as uppercase. The validator should reject any code entered in lowercase at creation time, or automatically convert it to uppercase ( in admin panel ).

For example:
Admin tries to save code test10 → validation error “Only uppercase letters and numbers allowed.”

Or admin enters test10 and it’s auto‑uppercased to TEST10 on save.

Actual Behaviour

  • Lowercase coupon codes (e.g., test10) can be created and saved in the admin panel without any warning.

  • When such a lowercase code (test10) is applied programmatically using:

    $this->cart->update([
      'coupon_code' => 'test10',
    ]);

    — it succeeds.

  • However, if you try to apply the same code with an uppercase letter (e.g., Test10):

    $this->cart->update([
      'coupon_code' => 'Test10',
    ]);

    — it fails.

  • method Discounts::validateCoupon returns true for both 'test10' and 'Test10'.

Steps To Reproduce:

  1. Create a coupon code in the admin panel
    Go to the admin panel and create a new discount with a lowercase code, e.g., test10. Save it.

  2. Apply the coupon code programmatically (lowercase)
    In your code, update the cart using:

    $this->cart->update([
      'coupon_code' => 'test10',
    ]);

    The coupon is applied successfully.

  3. Apply the coupon code programmatically (different capitalization)
    Now, try updating the cart using:

    $this->cart->update([
      'coupon_code' => 'Test10',
    ]);

    The operation fails—the coupon is not applied.

  4. Validate the coupon code with both cases
    Call the validation method for both variants:

    Discounts::validateCoupon('test10'); // returns true
    Discounts::validateCoupon('Test10'); // also returns true

    Both validations succeed, even though only the lowercase variant works when applying the coupon.

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