Skip to content

Stripe/Trans amount parser silently truncates on locale-mismatched separators #3379

Description

@robin-the-going-merry

Requested by: Michael Letellier

Moved from Strategy11/formidable-pro#6678 — the affected code only exists in this repo (Lite), not Pro.

Repro: On a currency where thousand_separator and decimal_separator are swapped from US convention (e.g. EUR: thousand=., decimal=,), enter an amount using US-style separators, e.g. 1,030.21.

Root cause: stripe/controllers/FrmTransLiteActionsController.php

  • get_amount_from_string() (:354) passes the raw string through unchanged: 1,030.21.
  • maybe_use_decimal() (:367) sees thousand_separator === '.', finds one . in the string with a 2-digit tail, assumes it's being used as a decimal point, and swaps it: str_replace('.', ',', ...)1,030,21.
  • normalize_number() (:392) strips the currency's thousand_separator (., none left to strip) then swaps decimal_separator ,., producing 1.030.21, then casts to float.
  • PHP's (float) cast on 1.030.21 stops parsing at the second ., silently returning 1.03.

Incorrect: 1,030.21 → amount sent to Stripe: 1.03 (or equivalent tiny-fraction result for any input with two separators in the "wrong" order for the currency).
Expected: either correctly parsed as 1030.21, or rejected/flagged — not silently mangled by ~1000x.

No validation catches this anywhere in the chain; it fails silently with a wrong charge amount, not an error.

Reported via: Help Scout #234168 (closed as customer education — told to remove separators entirely, which avoids the bug but does not fix the underlying parser).

Fix should make maybe_use_decimal/normalize_number either detect an ambiguous/contradictory separator pattern and reject it, or parse more defensively so a malformed amount never silently shrinks by orders of magnitude.

Once fixed, close/reference formidable-pro#6678.

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