Actions
Defect #9394
closedCustom date field only validating on regex and not a valid date
Start date:
2011-10-09
Due date:
% Done:
0%
Estimated time:
Resolution:
Fixed
Affected version:
Description
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
My Environment Info¶
Redmine 1.0.4.stable (MySQL)
Running using the latest Bitnami windows installer
Related issues
Updated by Jean-Philippe Lang about 13 years ago
- Status changed from New to Resolved
- Target version set to 1.2.3
- Affected version (unused) set to 1.2.2
- Resolution set to Fixed
- Affected version set to 1.2.2
Fixed with test in r7779, thanks.
Updated by Jean-Philippe Lang about 13 years ago
- Status changed from Resolved to Closed
Merged in r7998.
Actions