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

Fix numbers which start with country codes. #1

Merged
merged 1 commit into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/global_phone/territory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def strip_prefixes(string)
string_without_prefix = string.sub(national_prefix_for_parsing, transform_rule)
elsif starts_with_national_prefix?(string)
string_without_prefix = string[national_prefix.length..-1]
elsif starts_with_country_code?(string)
elsif !possible?(string) && starts_with_country_code?(string)
string_without_prefix = string[country_code.length..-1]
end

Expand Down
5 changes: 5 additions & 0 deletions test/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ContextTest < TestCase
:country_code => "44", :national_string => "2070313000"
end

test "parsing national number for given territory with leading country code" do
assert_parses "3914172422", :with_territory => :it,
:country_code => "39", :national_string => "3914172422"
end

test "parsing international number with prefix" do
assert_parses "00 1 3125551212", :with_territory => :gb,
:country_code => "1", :national_string => "3125551212"
Expand Down