-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
I'm noticing a different behavior between rust-phonenumber and the official Google libphonenumber library when parsing phone numbers with letters. I'm not sure if this is intentional or a bug.
The difference
When parsing +3367a829916:
- rust-phonenumber: converts to
+33672829916(letter 'a' → digit '2') - Google libphonenumber (Python): converts to
+3367829916(letter 'a' is removed)
Rust code:
use phonenumber::*;
fn main() {
let number = parse(None, "+3367a829916").expect("Invalid number");
let e164 = number.format().mode(Mode::E164).to_string();
println!("E. 164 number: {}", e164);
// Output: +33672829916
}Python code (official libphonenumber):
import phonenumbers
number = phonenumbers.parse("+3367a829916", None)
e164 = phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat. E164)
print(f"E.164 number: {e164}")
# Output: +3367829916My test expectation
In my tests, I expected this input to return an InvalidPhone error since it contains a letter in an invalid position for a French phone number:
// Test at tests/phone. rs:64: 13
// Expected: Err(InvalidPhone)
// Got: Ok("+33672829916")Question
Is this difference in behavior intentional (a feature), or should rust-phonenumber match the behavior of the official Google library?
I understand that vanity numbers (like "1-800-FLOWERS") should convert letters to digits, but I'm wondering if rust-phonenumber's conversion might be too broad compared to the original implementation.
Thanks for clarifying!
Metadata
Metadata
Assignees
Labels
No labels