]> source.dussan.org Git - redmine.git/commitdiff
Strip whitespace from integer custom field (#8317).
authorGo MAEDA <maeda@farend.jp>
Thu, 8 Nov 2018 13:01:06 +0000 (13:01 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 8 Nov 2018 13:01:06 +0000 (13:01 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17625 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/field_format.rb
test/unit/custom_field_test.rb

index 4d168b434bd6312813ba63258cb28502da506422..64fcdc6a4ea0aa8cdc0155078c153d61573c19be 100644 (file)
@@ -490,7 +490,7 @@ module Redmine
 
       def validate_single_value(custom_field, value, customized=nil)
         errs = super
-        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s =~ /^[+-]?\d+$/
+        errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s.strip =~ /^[+-]?\d+$/
         errs
       end
 
index bdf5d48422b10565d8230e67fc896f26ca47365e..b1d7f7ad7ff8b2e070cb6e602e9d3a491453d6a0 100644 (file)
@@ -206,6 +206,7 @@ class CustomFieldTest < ActiveSupport::TestCase
     assert f.valid_field_value?('')
     assert !f.valid_field_value?(' ')
     assert f.valid_field_value?('123')
+    assert f.valid_field_value?(' 123 ')
     assert f.valid_field_value?('+123')
     assert f.valid_field_value?('-123')
     assert !f.valid_field_value?('6abc')
@@ -219,6 +220,7 @@ class CustomFieldTest < ActiveSupport::TestCase
     assert f.valid_field_value?('')
     assert !f.valid_field_value?(' ')
     assert f.valid_field_value?('11.2')
+    assert f.valid_field_value?(' 11.2 ')
     assert f.valid_field_value?('-6.250')
     assert f.valid_field_value?('5')
     assert !f.valid_field_value?('6abc')