]> source.dussan.org Git - redmine.git/commitdiff
Reject non numeric values for numeric fields.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 10 Jul 2011 18:19:21 +0000 (18:19 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 10 Jul 2011 18:19:21 +0000 (18:19 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6228 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index 33fe2ec5fc949a50053a5425387dd45358fefaa0..b9be0851968ccc796b35dd1789c022e1373a00bc 100644 (file)
@@ -278,7 +278,11 @@ class Query < ActiveRecord::Base
       #  allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
       #  filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
       #end
-      filters[field] = {:operator => operator, :values => (values || ['']) }
+      values ||= ['']
+      if filter_options[:type] == :integer
+        values = values.select {|v| v.blank? || v.match(/^\d+(\.\d+)?$/) }
+      end
+      filters[field] = {:operator => operator, :values => values }
     end
   end
 
index d1d55bb2a6a45ec9f83baf0db4e223591bc707ef..95308ee0c114ae04a9cc6e6dedcb9bad0446c1a3 100644 (file)
@@ -101,6 +101,15 @@ class QueryTest < ActiveSupport::TestCase
     find_issues_with_query(query)
   end
   
+  def test_numeric_filter_should_not_accept_non_numeric_values
+    query = Query.new(:name => '_')
+    query.add_filter('estimated_hours', '=', ['a'])
+    
+    assert query.has_filter?('estimated_hours')
+    assert query.values_for('estimated_hours').empty?
+    assert !query.valid?
+  end
+  
   def test_operator_is_on_float
     Issue.update_all("estimated_hours = 171.2", "id=2")