Closed morgant closed 1 year ago
@morgant thanks for reporting, the issue comes with ability of phonelib to ignore specified country in case it doesn't match the phone prefix. I just released 0.7.1 version introducing new option Phonelib.ignore_plus
that allows to disable this behaviour.
By default this is turned off, so place Phonelib.ignore_plus = true
to your initializer.
Ruby: 2.7.4 Rails: 6.0.2 Phonelib: 0.7.0
Our application initially used the Phonelib ActiveRecord validator's
countries
option to specify all countries, but we have found this to be too permissive as the number of countries supported has grown. So, we're in the process of switching to using the validator'scountry_specifier
option, but have run into some inconsistencies in validation results.Specifically, in our test suite, we use a North Korean number for a number we don't expect to ever accept (the British Embassy in Pyongyang: "+850 2 381 7980"), but since switching to using
country_specifier
, it returns as valid.In one of our models, we went from the following validation:
To the following, with a new
phone_validation_country
method that returns an appropriate ISO3166 alpha2 string:But with a
contact_phone
of "+850 2 381 7980" andphone_validation_country
returning "US", it is considered valid.I believe I have narrowed this down to
Phonelib::Phone.parse
/Phonelib::Phone.new
/Phonelib::Phone#initialize
vsPhonelib::Phone#valid_for_country?
. For example:Note that
#valid?
returnstrue
when passed "US" as a country, though#valid_for_country?("US")
returnsfalse
.Some examples of other test numbers that are at least still consistent between
#valid?
and#valid_for_country?
(though I will note that the#countries
and#valid_countries
output are not necessarily what I would have expected):