Skip to content

Commit

Permalink
Merge pull request #183 from joost/fix_00_numbers
Browse files Browse the repository at this point in the history
Allow numbers starting with 00 country codes. Closes #175.
  • Loading branch information
Joost Hietbrink authored Sep 5, 2018
2 parents e6294a8 + f77ddb8 commit bde5dbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phony_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def self.normalize_number(number, options = {}, current_instance = nil)
def self.normalize_number_default_country(number, default_country_number)
# We try to add the default country number and see if it is a
# correct phone number. See https://github.com/joost/phony_rails/issues/87#issuecomment-89324426
unless number =~ /\A\(?\+/ # if we don't have a +
unless number =~ /\A\(?(\+|00)/ # if we don't have a + or 00
return "#{default_country_number}#{number}" if Phony.plausible?("#{default_country_number}#{number}") || !Phony.plausible?(number) || country_code_from_number(number).nil?
# If the number starts with ONE zero (two might indicate a country code)
# and this is a plausible number for the default_country
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/phony_rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ class NormalHome < ActiveRecord::Base
phone = PhonyRails.normalize_number(phone, default_country_code: 'DE')
expect(phone).to eq('+491751234567')
end

it 'should pass Github issue #175' do
phone = '0041 23456789'
phone = PhonyRails.normalize_number(phone, default_country_code: 'DE')
expect(phone).to eq('+4123456789')
end
end

it 'should not change original String' do
Expand Down

0 comments on commit bde5dbf

Please sign in to comment.