whisperfish / rust-phonenumber

Library for parsing, formatting and validating international phone numbers.
Apache License 2.0
154 stars 54 forks source link

National part of the number is truncated in some cases #76

Open paulll opened 1 month ago

paulll commented 1 month ago

Some RU/KZ/BY (and maybe other) numbers are truncated if national part of the number starts with same digit as national trunk prefix which is 8 in that case:

Also RU numbers are always 11 digits in E164 form, so that +7005553535 is impossible number.

assert_eq!(
    parser::parse(Some(country::RU), "+78005553535").unwrap().format().to_string(),
    "+78005553535"
);

assert_eq!(
    parser::parse(Some(country::RU), "88005553535").unwrap().format().to_string(),
    "+78005553535"
);

assert_eq!(
    parser::parse(Some(country::BY), "+375800111111").unwrap().format().to_string(),
    "+375800111111"
);

Google libphonenumber handles that cases correctly: 1, 2, 3

rubdos commented 1 month ago

Sounds like a duplicate of #68 to me, no?

direc85 commented 1 month ago

Not quite, since this is about dropping a number in the national part, and bug 68 is about handling/guessing the country code in itself.

Edit: It is a duplicate indeed; this one drops 8 and the linked bug drops 39. Missed that one, sorry!

paulll commented 1 month ago

I'm not sure if it makes a difference, but as far as I can see, 39 is a country code:

<territory id="IT" mainCountryForCode="true" countryCode="39" internationalPrefix="00"
               mobileNumberPortableRegion="true">

And 8 is a national prefix, while 7 is a country code.

<territory id="RU" mainCountryForCode="true" countryCode="7" leadingDigits="3[04-689]|[489]"
               preferredInternationalPrefix="8~10" internationalPrefix="810" nationalPrefix="8"
               mobileNumberPortableRegion="true">
rubdos commented 1 month ago

Let's leave both issues open, then!