summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-28 11:40:02 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-28 11:40:02 +0000
commit40abbfa82d97b1151b4cb904ce517a3cc43d5b86 (patch)
treede6db64b6b9a2625f121e3bf0ccfb4822cb21953
parent8d7fd10f908169bd413d9d18d0475c3f3256a4b9 (diff)
downloadredmine-40abbfa82d97b1151b4cb904ce517a3cc43d5b86.tar.gz
redmine-40abbfa82d97b1151b4cb904ce517a3cc43d5b86.zip
Backported r12938 (#16169).
git-svn-id: http://svn.redmine.org/redmine/branches/2.4-stable@12940 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/custom_field.rb2
-rw-r--r--test/unit/custom_field_test.rb8
2 files changed, 9 insertions, 1 deletions
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')