fix(utils): Allow characters to be included after normalizing numbers

Android's normalizing function stripped out characters too aggressively leading to false matches between different numbers. This commit introduces a faster normalizing function that includes characters.
This commit is contained in:
Inhishonor
2026-03-07 12:09:43 -08:00
parent 1200cb9008
commit c5f4fd54ab
2 changed files with 12 additions and 3 deletions
@@ -69,4 +69,14 @@ class PhoneNumberUtilsTest {
assertFalse(phoneNumberUtils.compare("123 456 7890", "234 567 8901"))
}
@Test
fun compare_formatted_SenderID_returnsTrue() {
assertTrue(phoneNumberUtils.compare("Vi-CARE-S", "ViCARES"))
}
@Test
fun compare_different_SenderID_returnsFalse() {
assertFalse(phoneNumberUtils.compare("VM-ViCARE-S", "VZ-ViCARE-S"))
}
}
@@ -68,9 +68,8 @@ class PhoneNumberUtils @Inject constructor(context: Context) {
return PhoneNumberUtils.formatNumber(number.toString(), countryCode) ?: number.toString()
}
fun normalizeNumber(number: String): String {
return PhoneNumberUtils.stripSeparators(number)
}
fun normalizeNumber(number: String): String =
number.filter { it.isLetterOrDigit() || it in "+*#" }
private fun parse(number: CharSequence): Phonenumber.PhoneNumber? {
return tryOrNull(false) { phoneNumberUtil.parse(number, countryCode) }