Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3314 from macmartine/master

Remove user-specified delimiter from start when no area code is present (in number_to_phone)
  • Loading branch information...
commit a5b0f914f16aac806a157dd4b6f3e3f3656d8396 2 parents 8cbe826 + 20728f5
@spastorino spastorino authored
View
2  actionpack/lib/action_view/helpers/number_helper.rb
@@ -69,7 +69,7 @@ def number_to_phone(number, options = {})
number.gsub!(/(\d{1,3})(\d{3})(\d{4}$)/,"(\\1) \\2#{delimiter}\\3")
else
number.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
- number.slice!(0, 1) if number.starts_with?('-')
+ number.slice!(0, 1) if number.starts_with?(delimiter) && !delimiter.blank?
end
str = []
View
1  actionpack/test/template/number_helper_test.rb
@@ -27,6 +27,7 @@ def test_number_to_phone
assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
assert_equal("(800) 555-1212 x 123", number_to_phone(8005551212, {:area_code => true, :extension => 123}))
assert_equal("800-555-1212", number_to_phone(8005551212, :extension => " "))
+ assert_equal("555.1212", number_to_phone(5551212, :delimiter => '.'))
assert_equal("800-555-1212", number_to_phone("8005551212"))
assert_equal("+1-800-555-1212", number_to_phone(8005551212, :country_code => 1))
assert_equal("+18005551212", number_to_phone(8005551212, :country_code => 1, :delimiter => ''))
Please sign in to comment.
Something went wrong with that request. Please try again.