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

UK 0203 numbers not handled correctly #261

Closed
Carpela opened this issue Jun 19, 2015 · 13 comments
Closed

UK 0203 numbers not handled correctly #261

Carpela opened this issue Jun 19, 2015 · 13 comments

Comments

@Carpela
Copy link

Carpela commented Jun 19, 2015

0203 numbers (London, UK) seem to not be recognised as UK numbers

[13] pry(main)> PhonyRails.normalize_number('02031234567', default_country_code:'GB', add_plus:false)
=> "2031234567"

0207 numbers are handled correctly.

[14] pry(main)> PhonyRails.normalize_number('02071234567', default_country_code:'GB', add_plus:false)
=> "442071234567"

With country code this works fine.

[15] pry(main)> PhonyRails.normalize_number('02031234567', country_code:'GB', add_plus:false)

=> "442031234567"

The issue appears to be the following:

[24] pry(main)> Phony.plausible?('02031234567')
=> true
[25] pry(main)> Phony.plausible?('02071234567')
=> false
[22] pry(main)> PhonyRails.country_code_from_number('02031234567')
=> "20"
[23] pry(main)> PhonyRails.country_code_from_number('02071234567')
=> nil

Not sure how to stop Phony thinking that an 0203 number is from Egypt...?

@Carpela
Copy link
Author

Carpela commented Jun 19, 2015

Apologies, asked the chap from PhonyRails who suggested I throw it your way.

@floere
Copy link
Owner

floere commented Jun 19, 2015

@Carpela Apologies for the first response – I was mistaken. This does seem like a PhonyRails issue, because it's PhonyRails' decision to not return a country code if a number does not seem to be plausible. If it would return the presumed country code, then it would be no issue.

@floere
Copy link
Owner

floere commented Jun 19, 2015

@Carpela In fact, looking more into it – I do believe PhonyRails's process may be slightly incorrect (or I may misunderstand its workings, of course).

Using vanilla Phony, we can see that if you add the CC for the UK, normalize, and check for plausibility:

$ ruby -e 'require "phony"; p Phony.plausible?(Phony.normalize("4402031234567"))'
true
$ ruby -e 'require "phony"; p Phony.plausible?(Phony.normalize("4402071234567"))'
true

@floere
Copy link
Owner

floere commented Jun 19, 2015

It may be a good idea to pull the PhonyRails maintainer in here.

@joost I like your default country code idea. I am wondering what is going wrong here – when I add the CC, then normalize, then check for plausibility, both numbers return true. What process are you using to either add the CC or not?

@floere
Copy link
Owner

floere commented Jun 30, 2015

@Carpela @joost Any updates?

@joost
Copy link

joost commented Jun 30, 2015

Will try to find some spare minutes tomorrow to have a look :)

@floere
Copy link
Owner

floere commented Aug 4, 2015

Closing this issue – just reopen it if you need to. Thanks! 💃

@Carpela
Copy link
Author

Carpela commented Nov 12, 2015

This one's still a bit of an annoying issue.
@joost

joost/phony_rails#95

It seems to be falling somewhere in the gap.
phony is (possibly correctly) saying this is a plausible egyptian number. Unfortunately it's also a plausible UK number....
phony_rails when trying to use the GB country code is checking if it's a foreign number first, whcih isn't a terrible idea, but in this case is turning things egyptian rather than respecting the default country code.

Not sure where to apply any change. It does seem to just be with 0203 numbers. (Which are quite a populate london number for businesses.

@floere
Copy link
Owner

floere commented Nov 12, 2015

I don't have any more information than I had when I wrote #261 (comment).

@Carpela
Copy link
Author

Carpela commented Nov 12, 2015

Ok. I could try something but I'd likely break it.... :)
It's a weird edge case, I guess. But somewhere in that gap it would be great if we could fix it.
I'm doing the following currently

def check_invalid_numbers
if self.phone =~ /^(203|0203)/
# this first clause picks up the UK numbers
if self.phone[0..3] == "0203"
self.phone[0..3] == "44203"
# This would bugger up egyptian numbers, I just don't happen to have any
elsif self.phone[0..2] == "203"
self.phone[0..2] == "44203"
end
end
end

@floere
Copy link
Owner

floere commented Nov 12, 2015

@Carpela I think it's great you found a solution and are making Phony work for you (or in this case, PhonyRails)! Unfortunately, I can't change Phony as it works as advertised (it can't do magic).

@joost
Copy link

joost commented Nov 12, 2015

Just had a minute to look into this. Please check joost/phony_rails#95 for a fix.

@floere
Copy link
Owner

floere commented Nov 12, 2015

@joost Cheers 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants