プロジェクト

全般

プロフィール

Vote #70804

完了

Custom date field only validating on regex and not a valid date

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Custom fields_14
対象バージョン:
開始日:
2011/10/09
期日:
進捗率:

0%

予定工数:
category_id:
14
version_id:
39
issue_org_id:
9394
author_id:
735
assigned_to_id:
0
comments:
2
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
38
ステータス-->[Closed]

説明

If you create a custom date field it looks like the validations are not correctly happening based on a valid date. It is only validating on this regex @/\d{4}-\d{2}-\d{2}$@

So 2011-10-33 is a valid value but October does not have 33 days.

The offending code is in Redmine/apps/models/custom_value.rb

In the Validate method

I added the following to the end of the date validation @&& begin; value.to_date; rescue; false end@

I only use git so I can't submit this as an svn patch.

Here is my modified code with the only changing being in the "when 'date'"

def validate
    if value.blank?
      errors.add(:value, :blank) if custom_field.is_required? and value.blank?    
    else
      errors.add(:value, :invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
      errors.add(:value, :too_short, :count => custom_field.min_length) if custom_field.min_length > 0 and value.length < custom_field.min_length
      errors.add(:value, :too_long, :count => custom_field.max_length) if custom_field.max_length > 0 and value.length > custom_field.max_length
    
      # Format specific validations
      case custom_field.field_format
      when 'int'
        errors.add(:value, :not_a_number) unless value =~ /^[+-]?\d+$/  
      when 'float'
        begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
      when 'date'
        errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ && begin; value.to_date; rescue; false end
      when 'list'
        errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
      end
    end
  end

h3. My Environment Info

Redmine 1.0.4.stable (MySQL)

Running using the latest Bitnami windows installer


journals

Fixed with test in r7779, thanks.
--------------------------------------------------------------------------------
Merged in r7998.
--------------------------------------------------------------------------------


related_issues

relates,Closed,12359,Version date field regex validation accepts invalid date

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0