mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix number_to_percentage
with Float::NAN
, Float::INFINITY
.
Closes #14405.
This is a follow-up to 9e997e9039
to restore
the documented behavior.
This commit is contained in:
parent
a0c1c18e4d
commit
378c8d2c99
4 changed files with 14 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
|||
* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY`
|
||||
as input.
|
||||
|
||||
Fixes #14405.
|
||||
|
||||
*Yves Senn*
|
||||
|
||||
* Add `include_hidden` option to `collection_check_boxes` helper.
|
||||
|
||||
*Vasiliy Ermolovich*
|
||||
|
|
|
@ -32,6 +32,9 @@ class NumberHelperTest < ActionView::TestCase
|
|||
assert_equal "100%", number_to_percentage(100, precision: 0)
|
||||
assert_equal "123.4%", number_to_percentage(123.400, precision: 3, strip_insignificant_zeros: true)
|
||||
assert_equal "1.000,000%", number_to_percentage(1000, delimiter: ".", separator: ",")
|
||||
assert_equal "98a%", number_to_percentage("98a")
|
||||
assert_equal "NaN%", number_to_percentage(Float::NAN)
|
||||
assert_equal "Inf%", number_to_percentage(Float::INFINITY)
|
||||
end
|
||||
|
||||
def test_number_with_delimiter
|
||||
|
|
|
@ -32,8 +32,7 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
formatted_string =
|
||||
case rounded_number
|
||||
when BigDecimal
|
||||
if BigDecimal === rounded_number && rounded_number.finite?
|
||||
s = rounded_number.to_s('F') + '0'*precision
|
||||
a, b = s.split('.', 2)
|
||||
a + '.' + b[0, precision]
|
||||
|
|
|
@ -79,6 +79,9 @@ module ActiveSupport
|
|||
assert_equal("123.4%", number_helper.number_to_percentage(123.400, :precision => 3, :strip_insignificant_zeros => true))
|
||||
assert_equal("1.000,000%", number_helper.number_to_percentage(1000, :delimiter => '.', :separator => ','))
|
||||
assert_equal("1000.000 %", number_helper.number_to_percentage(1000, :format => "%n %"))
|
||||
assert_equal("98a%", number_helper.number_to_percentage("98a"))
|
||||
assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN))
|
||||
assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue