Skip to content
This repository
Browse code

remove user-specified delimiter from start when no area code is prese…

…nt (in number_to_phone)
  • Loading branch information...
commit 20728f551c2a429fc7c29c6ac17b3f44b57526b9 1 parent f6c9349
Mac Martine authored
2  actionpack/lib/action_view/helpers/number_helper.rb
@@ -69,7 +69,7 @@ def number_to_phone(number, options = {})
69 69 number.gsub!(/(\d{1,3})(\d{3})(\d{4}$)/,"(\\1) \\2#{delimiter}\\3")
70 70 else
71 71 number.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
72   - number.slice!(0, 1) if number.starts_with?('-')
  72 + number.slice!(0, 1) if number.starts_with?(delimiter) && !delimiter.blank?
73 73 end
74 74
75 75 str = []
1  actionpack/test/template/number_helper_test.rb
@@ -27,6 +27,7 @@ def test_number_to_phone
27 27 assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
28 28 assert_equal("(800) 555-1212 x 123", number_to_phone(8005551212, {:area_code => true, :extension => 123}))
29 29 assert_equal("800-555-1212", number_to_phone(8005551212, :extension => " "))
  30 + assert_equal("555.1212", number_to_phone(5551212, :delimiter => '.'))
30 31 assert_equal("800-555-1212", number_to_phone("8005551212"))
31 32 assert_equal("+1-800-555-1212", number_to_phone(8005551212, :country_code => 1))
32 33 assert_equal("+18005551212", number_to_phone(8005551212, :country_code => 1, :delimiter => ''))

0 comments on commit 20728f5

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