DrHyde / perl-modules-Number-Phone

Number::Phone and friends
24 stars 31 forks source link

Fix application of national prefix transform rule #87

Closed mikeraynham closed 6 years ago

mikeraynham commented 6 years ago

libphonenumber only applies the national prefix transform rule if the last possible capture group of the national prefix rule regex matches. That is, it won't apply the transform rule if there are no prefixes to transform. Where there are no suitable captures, it will simply delete the matching prefix. See:

com.google.i18n.phonenumbers.maybeStripNationalPrefixAndCarrierCode()

The Number::Phone country stub files, however, always apply the transform rule. This can lead to cases where phone numbers are incorrectly converted to the wrong type. For example, the international format for Argentinian mobile numbers requires the trunk code 0 to be removed, 9 to be placed before the area code, and the mobile prefix 15 to be removed, so:

"0 3715 15 65 4320" => "+54 9 3715 65 4320"

But Number::Phone incorrectly does the same for fixed line numbers:

"0 3715 65 4320" => "+54 9 3715 65 4320"

It should be:

"0 3715 65 4320" => "+54 3715 65 4320"

This branch makes the Number::Phone country stub classes more closely follow the logic in libphonenumber.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.002%) to 99.936% when pulling 7adf8ad584252d4174dc530d32f563bce52b2165 on mikeraynham:maybe_strip_national_prefix into 59b1fe196bd08438df5469237a1fe48ce48020bb on DrHyde:master.

DrHyde commented 6 years ago

Thanks!

dracos commented 6 years ago

Thanks, sorry for missing this in https://github.com/DrHyde/perl-modules-Number-Phone/pull/81!

davidcantrelluk2 commented 5 years ago

As a follow-up to this, I've just deleted the tests for Mexico, as they've switched (as of a month ago) to a nice simple Everything Is Ten Digits plan, with no Lovecraftian weirdness. See https://en.wikipedia.org/wiki/Telephone_numbers_in_Mexico