Filter out illegal values to prevent raise of PostgreSQL exceptions, restored last test part removed with r7625 (#8371).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7628 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
78a8757846
commit
33f65c5a48
|
@ -333,6 +333,10 @@ class Query < ActiveRecord::Base
|
||||||
available_filters[field][:type] if available_filters.has_key?(field)
|
available_filters[field][:type] if available_filters.has_key?(field)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def allowed_values_for(field)
|
||||||
|
available_filters[field][:values] if available_filters.has_key?(field)
|
||||||
|
end
|
||||||
|
|
||||||
def operator_for(field)
|
def operator_for(field)
|
||||||
has_filter?(field) ? filters[field][:operator] : nil
|
has_filter?(field) ? filters[field][:operator] : nil
|
||||||
end
|
end
|
||||||
|
@ -649,6 +653,7 @@ class Query < ActiveRecord::Base
|
||||||
sql = ''
|
sql = ''
|
||||||
case operator
|
case operator
|
||||||
when "="
|
when "="
|
||||||
|
value &= allowed_values_for(field).collect {|val| val[1]} if value.present? && allowed_values_for(field).present?
|
||||||
if value.any?
|
if value.any?
|
||||||
case type_for(field)
|
case type_for(field)
|
||||||
when :date, :date_past
|
when :date, :date_past
|
||||||
|
@ -665,6 +670,7 @@ class Query < ActiveRecord::Base
|
||||||
sql = "1=0"
|
sql = "1=0"
|
||||||
end
|
end
|
||||||
when "!"
|
when "!"
|
||||||
|
value &= allowed_values_for(field).collect {|val| val[1]} if value.present? && allowed_values_for(field).present?
|
||||||
if value.any?
|
if value.any?
|
||||||
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
|
||||||
else
|
else
|
||||||
|
|
|
@ -162,7 +162,9 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
'!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
|
'!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
|
||||||
'tracker_id' => {
|
'tracker_id' => {
|
||||||
'3' => { :op => '=', :values => ['3'] },
|
'3' => { :op => '=', :values => ['3'] },
|
||||||
'=3' => { :op => '=', :values => ['3'] }},
|
'=3' => { :op => '=', :values => ['3'] },
|
||||||
|
'*' => { :op => '=', :values => ['*'] },
|
||||||
|
'!*' => { :op => '!', :values => ['*'] }},
|
||||||
'start_date' => {
|
'start_date' => {
|
||||||
'2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
|
'2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
|
||||||
'=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
|
'=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
|
||||||
|
|
Loading…
Reference in New Issue