Use block parameter rather than $1 during gsub! so ActiveSupport::SafeBuffer values aren't mangled.

Fixes #15064
This commit is contained in:
Mark J. Titorenko 2014-05-12 17:13:19 +01:00
parent 096be96db8
commit 9c8242ee6a
3 changed files with 13 additions and 1 deletions

@ -1,3 +1,12 @@
* Fixed an issue when using
`ActiveSupport::NumberHelper::NumberToDelimitedConverter` to
convert a value that is an `ActiveSupport::SafeBuffer` introduced
in 2da9d67.
For more info see #15064.
*Mark J. Titorenko*
* `TimeZone#parse` defaults the day of the month to '1' if any other date
components are specified. This is more consistent with the behavior of
`Time#parse`.

@ -13,7 +13,9 @@ def convert
def parts
left, right = number.to_s.split('.')
left.gsub!(DELIMITED_REGEX) { "#{$1}#{options[:delimiter]}" }
left.gsub!(DELIMITED_REGEX) do |digit_to_delimit|
"#{digit_to_delimit}#{options[:delimiter]}"
end
[left, right].compact
end
end

@ -97,6 +97,7 @@ def test_to_delimited
assert_equal("123,456,789.78901", number_helper.number_to_delimited(123456789.78901))
assert_equal("0.78901", number_helper.number_to_delimited(0.78901))
assert_equal("123,456.78", number_helper.number_to_delimited("123456.78"))
assert_equal("123,456.78", number_helper.number_to_delimited(ActiveSupport::SafeBuffer.new("123456.78")))
end
end