Skip to content
Browse files

Do not normalize an implausible phone.

  • Loading branch information...
1 parent 19c68e7 commit 1f300583ea1e700ffabc9d3ee554047bb4773ba8 @Jell Jell committed
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/phony_rails.rb
  2. +4 −0 spec/lib/phony_rails_spec.rb
View
2 lib/phony_rails.rb
@@ -25,7 +25,7 @@ def self.normalize_number(number, options = {})
# Add country_number if missing
number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
end
- number = Phony.normalize(number)
+ number = Phony.normalize(number) if Phony.plausible?(number)
return number.to_s
rescue
number # If all goes wrong .. we still return the original input.
View
4 spec/lib/phony_rails_spec.rb
@@ -34,6 +34,10 @@
PhonyRails.normalize_number('+31-70-4157134', :country_code => 'NL').should eql('31704157134')
PhonyRails.normalize_number('0323-2269497', :country_code => 'BE').should eql('323232269497')
end
+
+ it "should not normalize an implausible number" do
+ PhonyRails.normalize_number('01').should eql('01')
+ end
end
describe 'defining ActiveRecord#phony_normalized_method' do

0 comments on commit 1f30058

Please sign in to comment.
Something went wrong with that request. Please try again.