From: Jean-Philippe Lang Date: Fri, 28 Feb 2014 11:40:02 +0000 (+0000) Subject: Backported r12938 (#16169). X-Git-Tag: 2.4.4~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=40abbfa82d97b1151b4cb904ce517a3cc43d5b86;p=redmine.git Backported r12938 (#16169). git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12940 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index a4c20643c..00f1831d5 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -350,7 +350,7 @@ class CustomField < ActiveRecord::Base # Returns the error message for the given value regarding its format def validate_field_value_format(value) errs = [] - if value.present? + unless value.to_s == '' errs << ::I18n.t('activerecord.errors.messages.invalid') unless regexp.blank? or value =~ Regexp.new(regexp) errs << ::I18n.t('activerecord.errors.messages.too_short', :count => min_length) if min_length > 0 and value.length < min_length errs << ::I18n.t('activerecord.errors.messages.too_long', :count => max_length) if max_length > 0 and value.length > max_length diff --git a/test/unit/custom_field_test.rb b/test/unit/custom_field_test.rb index 44fd9a2f2..c42659d76 100644 --- a/test/unit/custom_field_test.rb +++ b/test/unit/custom_field_test.rb @@ -146,6 +146,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?('a' * 2) assert !f.valid_field_value?('a') assert !f.valid_field_value?('a' * 6) @@ -156,6 +157,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?('ABC') assert !f.valid_field_value?('abc') end @@ -165,6 +167,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?('1975-07-14') assert !f.valid_field_value?('1975-07-33') assert !f.valid_field_value?('abc') @@ -175,6 +178,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?('value2') assert !f.valid_field_value?('abc') end @@ -184,6 +188,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) 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') @@ -195,6 +200,7 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?('11.2') assert f.valid_field_value?('-6.250') assert f.valid_field_value?('5') @@ -206,9 +212,11 @@ class CustomFieldTest < ActiveSupport::TestCase assert f.valid_field_value?(nil) assert f.valid_field_value?('') + assert !f.valid_field_value?(' ') assert f.valid_field_value?([]) assert f.valid_field_value?([nil]) assert f.valid_field_value?(['']) + assert !f.valid_field_value?([' ']) assert f.valid_field_value?('value2') assert !f.valid_field_value?('abc')