Skip to content

Commit 2b84eea

Browse files
committed
Merge pull request rails#15072 from mjtko/fix/issue-15064
[Fixes rails#15064] Calling number_to_delimited on a ActiveSupport::SafeBuffer results in mangled output
2 parents 0626543 + 3703a8a commit 2b84eea

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

activesupport/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* Fixed an issue when using
2+
`ActiveSupport::NumberHelper::NumberToDelimitedConverter` to
3+
convert a value that is an `ActiveSupport::SafeBuffer` introduced
4+
in 2da9d67.
5+
6+
For more info see #15064.
7+
8+
*Mark J. Titorenko*
9+
110
* `TimeZone#parse` defaults the day of the month to '1' if any other date
211
components are specified. This is more consistent with the behavior of
312
`Time#parse`.

activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def convert
1313

1414
def parts
1515
left, right = number.to_s.split('.')
16-
left.gsub!(DELIMITED_REGEX) { "#{$1}#{options[:delimiter]}" }
16+
left.gsub!(DELIMITED_REGEX) do |digit_to_delimit|
17+
"#{digit_to_delimit}#{options[:delimiter]}"
18+
end
1719
[left, right].compact
1820
end
1921
end

activesupport/test/number_helper_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'abstract_unit'
22
require 'active_support/number_helper'
3+
require 'active_support/core_ext/string/output_safety'
34

45
module ActiveSupport
56
module NumberHelper
@@ -97,6 +98,7 @@ def test_to_delimited
9798
assert_equal("123,456,789.78901", number_helper.number_to_delimited(123456789.78901))
9899
assert_equal("0.78901", number_helper.number_to_delimited(0.78901))
99100
assert_equal("123,456.78", number_helper.number_to_delimited("123456.78"))
101+
assert_equal("123,456.78", number_helper.number_to_delimited("123456.78".html_safe))
100102
end
101103
end
102104

0 commit comments

Comments
 (0)