From 308a922d80331d139b576d44728e1c49d5321a7f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 11 Jul 2011 14:13:59 +0000 Subject: [PATCH] Validate date filters values. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6264 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 7 +++++++ test/unit/query_test.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/models/query.rb b/app/models/query.rb index ac41ab478..ab0b3320d 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -176,6 +176,13 @@ class Query < ActiveRecord::Base errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) } when :float errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) } + 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}$/) } + when ">t-", " '_') + query.add_filter('created_on', '=', ['a']) + + 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']) + + assert query.has_filter?('created_on') + assert !query.valid? + end def test_operator_date_equals query = Query.new(:name => '_') -- 2.39.5