Closed widescape closed 6 years ago
For me it works, see spec.
Thanks for the fast response and your work!
We can reproduce it when the default_country_code
is matching the country prefix:
The following test case fails:
it 'should pass Github issue #170' do
PhonyRails.default_country_code = 'DE'
phone = '(+49) 175 123 4567'
phone = PhonyRails.normalize_number(phone)
expect(phone).to eq('+491751234567')
end
it is passing when default_country_code is set to anything other than 'DE'
.
Hey @joost, I saw that the new version (v0.14.7) includes your spec for this issue. But as said, your spec does not cover our issue. The spec should be different:
it 'should pass Github issue #170' do
PhonyRails.default_country_code = 'DE'
phone = '(+49) 175 123 4567'
phone = PhonyRails.normalize_number(phone)
expect(phone).to eq('+491751234567')
end
Can you please change the spec? Thanks!
What I expect:
What I get instead:
How is that possible?
The issue seems to be that
PhonyRails.normalize_number_default_country(…)
looks for a+
at the first position of the string. If that fails, it appends the default country code and checks if that is a valid number.Unfortunately:
+49 175…
is a valid german mobile prefix+49 491 …
is a valid german local prefixSuggested solution
Try to detect the
+
and thedefault_country_number
within the first characters, not at the first position only.