From af0ba49ac68c601bffb6e93742c4758b531d086d Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Sat, 13 Jun 2026 13:53:28 -0400 Subject: [PATCH] fix(phone): handle autofill-injected country code prefix in cleanNumber When Android autofill suggests a phone number with a leading + (e.g. +12025551234), cleanNumber would blindly prepend the locale area code, producing a malformed string like 1+12025551234 that caused a NumberParseException in libphonenumber. Now detects the + prefix and passes the number directly to makeE164 without prepending. Signed-off-by: Brandon McAnsh --- .../com/flipcash/app/phone/PhoneUtils.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt index aaacb0f6a..d3a70b75b 100644 --- a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt +++ b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt @@ -88,17 +88,17 @@ class PhoneUtils @Inject constructor( } fun cleanNumber(number: String, locale: CountryLocale): String { - val areaCode = locale.phoneCode - val countryCode =locale.countryCode - val phoneInput = number - - val phoneNumberCombined = areaCode.toString() + phoneInput + val countryCode = locale.countryCode + val javaLocale = Locale(Locale.getDefault().language, countryCode) - val phoneNumber = phoneNumberCombined.makeE164( - Locale(Locale.getDefault().language, countryCode) - ) + if (number.trimStart().startsWith("+")) { + // Already has country code (e.g. from autofill), parse as-is + return number.makeE164(javaLocale) + } - return phoneNumber + val areaCode = locale.phoneCode + val phoneNumberCombined = areaCode.toString() + number + return phoneNumberCombined.makeE164(javaLocale) } private fun String.makeE164(locale: Locale? = null): String {