From 082aaf8a9dd7abfc2e04450e471ed80901215e5a Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Mon, 6 May 2013 14:33:11 +0200 Subject: [PATCH 1/2] if phone number has specified country_code then use number and do not add supplied country_code --- lib/phony_rails.rb | 8 +++++--- spec/lib/phony_rails_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/phony_rails.rb b/lib/phony_rails.rb index 3e60f52..6b90549 100644 --- a/lib/phony_rails.rb +++ b/lib/phony_rails.rb @@ -21,9 +21,11 @@ def self.normalize_number(number, options = {}) number = number.clone # Just to be sure, we don't want to change the original. number.gsub!(/[^\d\+]/, '') # Strips weird stuff from the number return if number.blank? - if country_number = country_number_for(options[:country_code] || options[:default_country_code]) - # Add country_number if missing - number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/ + if !number.starts_with?('+') + if country_number = country_number_for(options[:country_code] || options[:default_country_code]) + # Add country_number if missing + number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/ + end end number = Phony.normalize(number) if Phony.plausible?(number) return number.to_s diff --git a/spec/lib/phony_rails_spec.rb b/spec/lib/phony_rails_spec.rb index bfb50e9..e23271e 100644 --- a/spec/lib/phony_rails_spec.rb +++ b/spec/lib/phony_rails_spec.rb @@ -77,6 +77,10 @@ PhonyRails.normalize_number('010-1234123', :country_code => 'NL').should eql('31101234123') end + it "should normalize a number with a country_code different than the specified country_code" do + PhonyRails.normalize_number('+4790909090', :country_code => 'SE').should eql('4790909090') + end + it "should handle different countries" do PhonyRails.normalize_number('(030) 8 61 29 06', :country_code => 'DE').should eql('49308612906') PhonyRails.normalize_number('+43 664 3830412', :country_code => 'AT').should eql('436643830412') From 8e433d43a2f044d9b97e046361c17d61a6d61b98 Mon Sep 17 00:00:00 2001 From: Espen Antonsen Date: Mon, 6 May 2013 14:37:24 +0200 Subject: [PATCH 2/2] The source :rubygems is deprecated because HTTP requests are insecure. --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index f9fad35..333e99d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' # Preempt the default loading so that we don't get an unqualified Country class imported. gem 'countries', :require => 'iso3166' diff --git a/Gemfile.lock b/Gemfile.lock index b48ef8c..3c3675c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ PATH phony (>= 1.7.7) GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: activemodel (3.2.13) activesupport (= 3.2.13)