From c5eff3dae254481d038fe482466d2075b63b0338 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 8 Nov 2018 13:01:06 +0000 Subject: [PATCH] Strip whitespace from integer custom field (#8317). Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@17625 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/field_format.rb | 2 +- test/unit/custom_field_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 4d168b434..64fcdc6a4 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -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 diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index bdf5d4842..b1d7f7ad7 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -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') -- 2.39.5