Skip to content

Commit

Permalink
reverting decoupling of NumberHelper from safe_join and adding tests …
Browse files Browse the repository at this point in the history
…for escaping of delimiters and separators
amutz committed May 18, 2012
1 parent 476ef2d commit 2c423b3
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/number_helper.rb
Original file line number Diff line number Diff line change
@@ -254,7 +254,7 @@ def number_with_delimiter(number, options = {})

parts = number.to_s.to_str.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
parts.join(options[:separator]).html_safe
safe_join(parts, options[:separator])
end

# Formats a +number+ with the specified level of
2 changes: 2 additions & 0 deletions actionpack/test/template/number_helper_test.rb
Original file line number Diff line number Diff line change
@@ -78,6 +78,8 @@ def test_number_with_delimiter_with_options_hash
assert_equal '12,345,678-05', number_with_delimiter(12345678.05, :separator => '-')
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.')
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',')
assert_equal '1&lt;script&gt;&lt;/script&gt;01', number_with_delimiter(1.01, :separator => "<script></script>")
assert_equal '1&lt;script&gt;&lt;/script&gt;000', number_with_delimiter(1000, :delimiter => "<script></script>")
end

def test_number_with_precision
1 change: 1 addition & 0 deletions activesupport/lib/active_support/testing/performance.rb
Original file line number Diff line number Diff line change
@@ -196,6 +196,7 @@ def self.[](name)

class Base
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::OutputSafetyHelper

attr_reader :total

0 comments on commit 2c423b3

Please sign in to comment.