]> source.dussan.org Git - redmine.git/commitdiff
Don't use #downcase on search tokens, let the database handle it (#18537).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 13 Dec 2014 18:36:35 +0000 (18:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 13 Dec 2014 18:36:35 +0000 (18:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13754 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/welcome/index.html.erb
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
test/unit/search_test.rb

index 2d4fdfc0599478f7c696d8561c599094e89d55e2..000f52e30c36a8b4fa432c04526d92d54fb7c3d8 100644 (file)
@@ -1,5 +1,7 @@
 <h2><%= l(:label_home) %></h2>
 
+<%= "Ö".downcase %>
+
 <div class="splitcontentleft">
   <%= textilizable Setting.welcome_text %>
   <% if @news.any? %>
index fa5fa202b23159d590d865a7df38cd0b7713b622..37c8b400dbb8110a407acba05d172d076480bb0e 100644 (file)
@@ -86,7 +86,7 @@ module Redmine
             columns = searchable_options[:columns]
             columns = columns[0..0] if options[:titles_only]
 
-            token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"}
+            token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE LOWER(?))"}
 
             if !options[:titles_only] && searchable_options[:search_custom_fields]
               searchable_custom_fields = CustomField.where(:type => "#{self.name}CustomField", :searchable => true)
@@ -97,7 +97,7 @@ module Redmine
               fields_by_visibility.each do |visibility, fields|
                 ids = fields.map(&:id).join(',')
                 sql = "#{table_name}.id IN (SELECT cfs.customized_id FROM #{CustomValue.table_name} cfs" +
-                  " WHERE cfs.customized_type='#{self.name}' AND cfs.customized_id=#{table_name}.id AND LOWER(cfs.value) LIKE ?" +
+                  " WHERE cfs.customized_type='#{self.name}' AND cfs.customized_id=#{table_name}.id AND LOWER(cfs.value) LIKE LOWER(?)" +
                   " AND cfs.custom_field_id IN (#{ids})" +
                   " AND #{visibility})"
                 token_clauses << sql
@@ -106,7 +106,7 @@ module Redmine
 
             sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ')
 
-            tokens_conditions = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
+            tokens_conditions = [sql, * (tokens.collect {|w| "%#{w}%"} * token_clauses.size).sort]
 
             scope = (searchable_options[:scope] || self)
             if scope.is_a? Proc
index c98982e8aebb7e65a985782740e9050435400372..48f39033dafeba5b106c4e87c550c71ea4d2b33c 100644 (file)
@@ -1,3 +1,5 @@
+# encoding: utf-8
+#
 # Redmine - project management software
 # Copyright (C) 2006-2014  Jean-Philippe Lang
 #
@@ -137,6 +139,13 @@ class SearchTest < ActiveSupport::TestCase
     assert_equal issue, r.first
   end
 
+  def test_search_should_not_use_ruby_downcase
+    issue = Issue.generate!(:subject => "Special chars: ÖÖ")
+    r = Issue.search_results('%ÖÖ%')
+    assert_equal 1, r.size
+    assert_equal issue, r.first
+  end
+
   private
 
   def remove_permission(role, permission)