{"action":"created","issue":{"url":"https://api.github.com/repos/daddyz/phonelib/issues/78","repository_url":"https://api.github.com/repos/daddyz/phonelib","labels_url":"https://api.github.com/repos/daddyz/phonelib/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/daddyz/phonelib/issues/78/comments","events_url":"https://api.github.com/repos/daddyz/phonelib/issues/78/events","html_url":"https://github.com/daddyz/phonelib/issues/78","id":160480762,"number":78,"title":"Some Norway phone numbers returned as US","user":{"login":"pduey","id":514776,"avatar_url":"https://avatars.githubusercontent.com/u/514776?v=3","gravatar_id":"","url":"https://api.github.com/users/pduey","html_url":"https://github.com/pduey","followers_url":"https://api.github.com/users/pduey/followers","following_url":"https://api.github.com/users/pduey/following{/other_user}","gists_url":"https://api.github.com/users/pduey/gists{/gist_id}","starred_url":"https://api.github.com/users/pduey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pduey/subscriptions","organizations_url":"https://api.github.com/users/pduey/orgs","repos_url":"https://api.github.com/users/pduey/repos","events_url":"https://api.github.com/users/pduey/events{/privacy}","received_events_url":"https://api.github.com/users/pduey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-15T17:36:21Z","updated_at":"2016-06-16T13:33:55Z","closed_at":null,"body":"\r\n```\r\nPhonelib.parse(\"+47 904 48 617\").country\r\n=> \"NO\"\r\nPhonelib.parse(\"+47 924 48 617\").country\r\n=> \"US\"`\r\n```\r\nNote the 4th number. Works with 0 or 1, but > 1 it returns US.\r\n\r\nTesting against libphonenumber directly works as expected:\r\n\r\n[https://libphonenumber.appspot.com/phonenumberparser?number=%2B47%20924%2048%20617](url)"},"comment":{"url":"https://api.github.com/repos/daddyz/phonelib/issues/comments/226486079","html_url":"https://github.com/daddyz/phonelib/issues/78#issuecomment-226486079","issue_url":"https://api.github.com/repos/daddyz/phonelib/issues/78","id":226486079,"user":{"login":"pduey","id":514776,"avatar_url":"https://avatars.githubusercontent.com/u/514776?v=3","gravatar_id":"","url":"https://api.github.com/users/pduey","html_url":"https://github.com/pduey","followers_url":"https://api.github.com/users/pduey/followers","following_url":"https://api.github.com/users/pduey/following{/other_user}","gists_url":"https://api.github.com/users/pduey/gists{/gist_id}","starred_url":"https://api.github.com/users/pduey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pduey/subscriptions","organizations_url":"https://api.github.com/users/pduey/orgs","repos_url":"https://api.github.com/users/pduey/repos","events_url":"https://api.github.com/users/pduey/events{/privacy}","received_events_url":"https://api.github.com/users/pduey/received_events","type":"User","site_admin":false},"created_at":"2016-06-16T13:33:55Z","updated_at":"2016-06-16T13:33:55Z","body":"I stepped through the code and figured out the problem. I think it's a bug.\r\n\r\nMy default country is set to US. Since I'm calling parse without the optional country parameter, it attempts to match the number on the default country. If that fails because the number is not valid in that country, then it iterates through all the countries and finds any that match:\r\n\r\n- (479) 044-8617 is NOT a valid US number, so it eventually finds Norway.\r\n- (479) 244-8617 IS a valid US number, so it never checks any other countries.\r\n\r\nI think that by including the leading '+' sign, i.e., a e164 formatted number, it should not use the default country at all. It should only try the country that matches the e164 formatted number. I'm using two other libraries that integrate with libphonenumber and that's how it's done (e.g., see link above)\r\n\r\nIf the maintainer agrees, I can do a pull request. Perhaps add it as an option for backwards compatibility.\r\n"}}
{"actor":{"display_login":"pduey"}}