From 6c5b29bb681ba1f11de2c04e78de1d306bcf7883 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 11 Jul 2011 14:36:43 +0000 Subject: [PATCH] More accurate date validation. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6265 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 2 +- test/unit/query_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/query.rb b/app/models/query.rb index ab0b3320d..4ea344b5a 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -179,7 +179,7 @@ class Query < ActiveRecord::Base when :date, :date_past case operator_for(field) when "=", ">=", "<=", "><" - errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d{4}-\d{2}-\d{2}$/) } + errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) } when ">t-", " '_') + query.add_filter('created_on', '=', ['2011-01-34']) + + assert query.has_filter?('created_on') + assert !query.valid? + end + def test_relative_date_filter_should_not_accept_non_integer_values query = Query.new(:name => '_') query.add_filter('created_on', '>t-', ['a']) -- 2.39.5