Merge pull request #43106 from flavorjones/flavorjones-activesupport-number-converter-valid-float
Avoid use of exceptions to detect invalid floats
This commit is contained in:
commit
4d3a2c09c8
|
@ -1,3 +1,8 @@
|
|||
* Improves the performance of ActionView::Helpers::NumberHelper formatters by avoiding the use of
|
||||
exceptions as flow control.
|
||||
|
||||
*Mike Dalessio*
|
||||
|
||||
* `preload_link_tag` properly inserts `as` attributes for files with `image` MIME types, such as JPG or SVG.
|
||||
|
||||
*Nate Berkopec*
|
||||
|
|
|
@ -448,9 +448,8 @@ module ActionView
|
|||
end
|
||||
|
||||
def parse_float(number, raise_error)
|
||||
Float(number)
|
||||
rescue ArgumentError, TypeError
|
||||
raise InvalidNumberError, number if raise_error
|
||||
result = Float(number, exception: false)
|
||||
raise InvalidNumberError, number if result.nil? && raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
* Improves the performance of ActiveSupport::NumberHelper formatters by avoiding the use of
|
||||
exceptions as flow control.
|
||||
|
||||
*Mike Dalessio*
|
||||
|
||||
* Removed rescue block from `ActiveSupport::Cache::RedisCacheStore#handle_exception`
|
||||
|
||||
Previously, if you provided a `error_handler` to `redis_cache_store`, any errors thrown by
|
||||
|
|
|
@ -99,8 +99,6 @@ module ActiveSupport
|
|||
# number_to_currency(1234567890.506, locale: :fr) # => "1 234 567 890,51 €"
|
||||
# number_to_currency('123a456') # => "$123a456"
|
||||
#
|
||||
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
||||
#
|
||||
# number_to_currency(-0.456789, precision: 0)
|
||||
# # => "$0"
|
||||
# number_to_currency(-1234567890.50, negative_format: '(%u%n)')
|
||||
|
|
|
@ -174,9 +174,7 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
def valid_float?
|
||||
Float(number)
|
||||
rescue ArgumentError, TypeError
|
||||
false
|
||||
Float(number, exception: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue