]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5198 search box with '_' (underscore) does not display expected results when...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 10 Oct 2014 12:18:00 +0000 (14:18 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 10 Oct 2014 12:18:00 +0000 (14:18 +0200)
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb

index a080bc1881d04f6a7643468017aaf3d61350e95f..410d59f601f982dec73dd635f1090520a420b213 100644 (file)
@@ -27,9 +27,13 @@ class Api::ComponentsController < Api::ApiController
     search = params[:s]
     bad_request("Minimum search is #{ResourceIndex::MIN_SEARCH_SIZE} characters") if search.empty? || search.to_s.size<ResourceIndex::MIN_SEARCH_SIZE
 
+    # SONAR-5198 Escape '_' on Oracle and MsSQL
+    dialect = java_facade.getDatabase().getDialect().getId()
+    additional_escape = dialect == 'oracle' || dialect == 'mssql' ? "ESCAPE '\\'" : ''
+
     key = escape_like(search).downcase
     results = ResourceIndex.all(:select => 'distinct(resource_id),root_project_id,qualifier,name_size', # optimization to not load unused columns like 'kee'
-                                :conditions => ['kee like ?', key + '%'],
+                                :conditions => ['kee like ? ' + additional_escape, key + '%'],
                                 :order => 'name_size')
 
     results = select_authorized(:user, results)