From bb6ab63ae60713b9fddef4ec4767c2d4591ec9a3 Mon Sep 17 00:00:00 2001 From: Joost Hietbrink Date: Wed, 5 Sep 2018 22:03:50 +0200 Subject: [PATCH 1/2] Allow numbers starting with 00 country codes. Closes #175. --- lib/phony_rails.rb | 2 +- spec/lib/phony_rails_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/phony_rails.rb b/lib/phony_rails.rb index c6530c8..3145b49 100644 --- a/lib/phony_rails.rb +++ b/lib/phony_rails.rb @@ -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 diff --git a/spec/lib/phony_rails_spec.rb b/spec/lib/phony_rails_spec.rb index f5aca9d..2577fa6 100644 --- a/spec/lib/phony_rails_spec.rb +++ b/spec/lib/phony_rails_spec.rb @@ -224,6 +224,13 @@ 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 From f77ddb8910d98fe631f19e5cfa4b2d8925d66465 Mon Sep 17 00:00:00 2001 From: Joost Hietbrink Date: Wed, 5 Sep 2018 22:30:19 +0200 Subject: [PATCH 2/2] Rubocop fix. --- spec/lib/phony_rails_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/phony_rails_spec.rb b/spec/lib/phony_rails_spec.rb index 2577fa6..426c6e7 100644 --- a/spec/lib/phony_rails_spec.rb +++ b/spec/lib/phony_rails_spec.rb @@ -230,7 +230,6 @@ class NormalHome < ActiveRecord::Base phone = PhonyRails.normalize_number(phone, default_country_code: 'DE') expect(phone).to eq('+4123456789') end - end it 'should not change original String' do