Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberHelper.number_with_delimiter should html_escape both delimiters and separators #6355

Merged
merged 1 commit into from
May 18, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/number_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def number_with_delimiter(number, options = {})


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply use safe_join back again?

end end


# Formats a +number+ with the specified level of # Formats a +number+ with the specified level of
Expand Down
2 changes: 2 additions & 0 deletions actionpack/test/template/number_helper_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 => '-')
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.') 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 '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 end


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


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


attr_reader :total attr_reader :total


Expand Down