mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 17:56:03 +01:00
Use sanitize_sql_like in Query#sql_contains (#35073).
Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@21232 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1441,6 +1441,7 @@ class Query < ActiveRecord::Base
|
|||||||
prefix = '%' if options[:ends_with]
|
prefix = '%' if options[:ends_with]
|
||||||
suffix = '%' if options[:starts_with]
|
suffix = '%' if options[:starts_with]
|
||||||
prefix = suffix = '%' if prefix.nil? && suffix.nil?
|
prefix = suffix = '%' if prefix.nil? && suffix.nil?
|
||||||
|
value = queried_class.sanitize_sql_like value
|
||||||
queried_class.send(
|
queried_class.send(
|
||||||
:sanitize_sql_for_conditions,
|
:sanitize_sql_for_conditions,
|
||||||
[Redmine::Database.like(db_field, '?', :match => options[:match]), "#{prefix}#{value}#{suffix}"])
|
[Redmine::Database.like(db_field, '?', :match => options[:match]), "#{prefix}#{value}#{suffix}"])
|
||||||
|
|||||||
@@ -2811,4 +2811,19 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sql_contains_should_escape_value
|
||||||
|
i = Issue.generate! subject: 'Sanitize test'
|
||||||
|
query = IssueQuery.new(:project => nil, :name => '_')
|
||||||
|
query.add_filter('subject', '~', ['te%t'])
|
||||||
|
assert_equal 0, query.issue_count
|
||||||
|
|
||||||
|
i.update_column :subject, 'Sanitize te%t'
|
||||||
|
assert_equal 1, query.issue_count
|
||||||
|
|
||||||
|
i.update_column :subject, 'Sanitize te_t'
|
||||||
|
query = IssueQuery.new(:project => nil, :name => '_')
|
||||||
|
query.add_filter('subject', '~', ['te_t'])
|
||||||
|
assert_equal 1, query.issue_count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user