diff options
author | Yoshiyuki Kinjo <yskkin@gmail.com> | 2018-09-06 20:02:12 +0900 |
---|---|---|
committer | Yoshiyuki Kinjo <yskkin@gmail.com> | 2018-09-07 16:17:15 +0900 |
commit | ba406d9c220c211439820271aabcf83395c60957 (patch) | |
tree | ba6970b943bbe976d875a63464f836c65ac7fe56 /activemodel/lib/active_model | |
parent | 54a9dbf5f19e128a2da851707fdaf34868b50078 (diff) | |
download | rails-ba406d9c220c211439820271aabcf83395c60957.tar.gz rails-ba406d9c220c211439820271aabcf83395c60957.tar.bz2 rails-ba406d9c220c211439820271aabcf83395c60957.zip |
Fix non_numeric_string?
For example, dirty checking was not right for the following case:
```
model.int_column = "+5"
model.float_column = "0.5E+1"
model.decimal_column = "0.5e-3"
```
It is enough to see whether leading character is a digit for avoiding
invalid numeric expression like 'wibble' to be type-casted to 0, as
this method's comment says.
Fixes #33801
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/type/helpers/numeric.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/type/helpers/numeric.rb b/activemodel/lib/active_model/type/helpers/numeric.rb index 16e14f9e5f..473cdb0c67 100644 --- a/activemodel/lib/active_model/type/helpers/numeric.rb +++ b/activemodel/lib/active_model/type/helpers/numeric.rb @@ -29,7 +29,7 @@ module ActiveModel # 'wibble'.to_i will give zero, we want to make sure # that we aren't marking int zero to string zero as # changed. - value.to_s !~ /\A-?\d+\.?\d*\z/ + !/\A[-+]?\d+/.match?(value.to_s) end end end |