globalesim: the Pay button can no longer be enabled with a blank CVC
- Commit
c518e812cbe9838d9d7bb04c4225db2e2c06cfd0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 04:03 UTC (5 days ago)
- Parents
170943d
validCard gated on cvcError(...) != null, but cvcError by design returns null for blank input (untouched fields show no inline error), so a blank or whitespace CVC produced a non-null ValidCard with cvc="" — the sheet enabled Pay and the purchase only failed at Stripe's confirm. The number and expiry blanks were already caught by their parsers; the CVC lacked the parse-level re-check the other fields get for free. validCard now requires the CVC itself to be 3-4 digits after the unchanged display gate; cvcError's blank-is-silent display behaviour is untouched, and the sheet already keys Pay off validCard. New test pins blank/whitespace rejection and '123' still passing (failed pre-fix). Purchase polling, quote math, activation codes and persistence were audited and cleared. Verified: :globalesim:testDevUnitTest 63 tests and lint pass.
Diff
globalesim/src/main/java/com/vayunmathur/globalesim/domain/CardValidation.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/domain/CardValidation.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/CardValidation.ktindex 8b6bafb2b5..10247bd302 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/domain/CardValidation.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/CardValidation.kt@@ -93,6 +93,10 @@ object CardValidation { if (numberError(numberRaw) != null) return null if (expiryError(expiryRaw) != null) return null if (cvcError(cvcRaw) != null) return null+ // cvcError is null for a blank field by design (untouched shows no+ // inline error), so gate validity on the CVC itself: number/expiry+ // blanks are caught by the parse re-checks below, a blank CVC was not.+ if (cvcRaw.length !in 3..4 || !DIGITS.matches(cvcRaw)) return null val number = cleanNumber(numberRaw) ?: return null val (month, year) = parseExpiry(expiryRaw) ?: return null return ValidCard(number, month, year, cvcRaw)
globalesim/src/test/java/com/vayunmathur/globalesim/domain/CardValidationTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/domain/CardValidationTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/CardValidationTest.ktindex a08b2fec9c..c1cd34d2fd 100644--- a/globalesim/src/test/java/com/vayunmathur/globalesim/domain/CardValidationTest.kt+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/CardValidationTest.kt@@ -60,6 +60,22 @@ class CardValidationTest { assertNotNull(CardValidation.cvcError("12a")) } + @Test+ fun validCardRejectsBlankCvc() {+ // Regression: cvcError("") is null by design (an untouched field+ // shows no inline error), but validCard must not treat a blank CVC+ // as valid — the sheet enables Pay on validCard != null, so an+ // empty/whitespace CVC used to reach Stripe's confirm and fail+ // there instead of being gated locally. Number and expiry blanks+ // were already caught by their parse re-checks; CVC had none.+ val now = Calendar.getInstance()+ val futureYear = (now.get(Calendar.YEAR) + 2) % 100+ val expiry = "08/%02d".format(futureYear)+ assertNull(CardValidation.validCard("4242 4242 4242 4242", expiry, ""))+ assertNull(CardValidation.validCard("4242 4242 4242 4242", expiry, " "))+ assertNotNull(CardValidation.validCard("4242 4242 4242 4242", expiry, "123"))+ }+ @Test fun validCardRoundTrip() { val now = Calendar.getInstance()