aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMark J. Titorenko <mark@titorenko.net>2014-05-12 17:13:19 +0100
committerMark J. Titorenko <mark@titorenko.net>2014-05-12 17:13:19 +0100
commit9c8242ee6a6ac33bdab26a3960e101d1ebb74bf5 (patch)
tree71d2c15c98b04555cbb8ef97a878b19e1b96fbb8 /activesupport
parent096be96db894854a199ce8cf9a8edeca0f203966 (diff)
downloadrails-9c8242ee6a6ac33bdab26a3960e101d1ebb74bf5.tar.gz
rails-9c8242ee6a6ac33bdab26a3960e101d1ebb74bf5.tar.bz2
rails-9c8242ee6a6ac33bdab26a3960e101d1ebb74bf5.zip
Use block parameter rather than `$1` during `gsub!` so `ActiveSupport::SafeBuffer` values aren't mangled.
Fixes #15064
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md9
-rw-r--r--activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb4
-rw-r--r--activesupport/test/number_helper_test.rb1
3 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 8d16898c80..68b327e0ad 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -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`.
diff --git a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb
index 6405afc9a6..d85cc086d7 100644
--- a/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb
+++ b/activesupport/lib/active_support/number_helper/number_to_delimited_converter.rb
@@ -13,7 +13,9 @@ module ActiveSupport
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
diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb
index 9bdb92024e..b220fd4232 100644
--- a/activesupport/test/number_helper_test.rb
+++ b/activesupport/test/number_helper_test.rb
@@ -97,6 +97,7 @@ module ActiveSupport
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