Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Country code wrapped in brackets is not recognized #170

Closed
widescape opened this issue Nov 24, 2017 · 3 comments
Closed

Country code wrapped in brackets is not recognized #170

widescape opened this issue Nov 24, 2017 · 3 comments

Comments

@widescape
Copy link

widescape commented Nov 24, 2017

What I expect:

PhonyRails.normalize_number('(+49) 175 123 4567') => "+491751234567"

What I get instead:

PhonyRails.normalize_number('(+49) 175 123 4567') => "+49491751234567"
# The country code '49' appears twice

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:

Suggested solution

Try to detect the + and the default_country_number within the first characters, not at the first position only.

joost pushed a commit that referenced this issue Nov 27, 2017
@joost
Copy link
Owner

joost commented Nov 27, 2017

For me it works, see spec.

@joost joost closed this as completed Nov 27, 2017
@p0wl
Copy link

p0wl commented Nov 30, 2017

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'.

@p0wl
Copy link

p0wl commented May 28, 2018

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!

joost pushed a commit that referenced this issue Sep 5, 2018
joost pushed a commit that referenced this issue Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants