diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2019-01-22 15:33:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-22 15:33:54 -0500 |
commit | ea6a488f51f439854bf3c528e4225eb45f767d00 (patch) | |
tree | e976030770f2bfe896efa47afdf01860eb60e1e3 /activemodel/lib/active_model/validations/numericality.rb | |
parent | 0815474d2f3d98e6d6844adaa771cf08ca1b5616 (diff) | |
parent | f01e38509c442903edaf12f23749193ce1f2d1d9 (diff) | |
download | rails-ea6a488f51f439854bf3c528e4225eb45f767d00.tar.gz rails-ea6a488f51f439854bf3c528e4225eb45f767d00.tar.bz2 rails-ea6a488f51f439854bf3c528e4225eb45f767d00.zip |
Merge pull request #35010 from Edouard-chin/ec-numericality-validator-fix
Fix NumericalityValidator on object responding to `to_f`:
Diffstat (limited to 'activemodel/lib/active_model/validations/numericality.rb')
-rw-r--r-- | activemodel/lib/active_model/validations/numericality.rb | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index c5997283ea..9cb8b543b0 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -10,7 +10,6 @@ module ActiveModel RESERVED_OPTIONS = CHECKS.keys + [:only_integer] INTEGER_REGEX = /\A[+-]?\d+\z/ - DECIMAL_REGEX = /\A[+-]?\d+\.?\d*(e|e[+-])?\d+\z/ def check_validity! keys = CHECKS.keys - [:odd, :even] @@ -92,8 +91,8 @@ module ActiveModel raw_value elsif is_integer?(raw_value) raw_value.to_i - elsif is_decimal?(raw_value) && !is_hexadecimal_literal?(raw_value) - BigDecimal(raw_value) + elsif !is_hexadecimal_literal?(raw_value) + Kernel.Float(raw_value).to_d end end @@ -101,12 +100,8 @@ module ActiveModel INTEGER_REGEX.match?(raw_value.to_s) end - def is_decimal?(raw_value) - DECIMAL_REGEX.match?(raw_value.to_s) - end - def is_hexadecimal_literal?(raw_value) - /\A0[xX]/.match?(raw_value) + /\A0[xX]/.match?(raw_value.to_s) end def filtered_options(value) |