Skip to content

Question: Different letter handling behavior compared to Google libphonenumber #100

@Itsoon

Description

@Itsoon

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: +3367829916

My 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

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