aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-02-07 18:20:21 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-02-07 18:20:21 +0100
commit856243d53548ef170facc3b68988c05de1f072af (patch)
tree023202d94fec3534a98503a53cd0f6d151753020 /sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
parent44f87ddcb7c15343b6bed710c12d9a440315b08b (diff)
downloadsonarqube-856243d53548ef170facc3b68988c05de1f072af.tar.gz
sonarqube-856243d53548ef170facc3b68988c05de1f072af.zip
SONAR-3909 % and _ should be taken into account as any other character by the search engine
Diffstat (limited to 'sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
index 848a1e18a9f..9b2012b670c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
@@ -23,7 +23,7 @@ class SearchController < ApplicationController
SECTION=Navigation::SECTION_HOME
- # Do not exceed 1000 because of the Oracle limition on IN statements
+ # Do not exceed 1000 because of the Oracle limitation on IN statements
MAX_RESULTS = 6
def index
@@ -31,7 +31,8 @@ class SearchController < ApplicationController
search = params[:s]
bad_request("Minimum search is #{ResourceIndex::MIN_SEARCH_SIZE} characters") if search.empty? || search.to_s.size<ResourceIndex::MIN_SEARCH_SIZE
- key = search.downcase
+ key = escape_like(search).downcase
+ puts "#### "+ key.to_s
results = ResourceIndex.find(:all,
:select => 'distinct(resource_id),root_project_id,qualifier,name_size', # optimization to not load unused columns like 'kee'
:conditions => ["kee like ?", key + '%'],
@@ -63,6 +64,7 @@ class SearchController < ApplicationController
end
private
+
def fix_qualifier(q)
case q
when 'CLA' then
@@ -71,4 +73,9 @@ class SearchController < ApplicationController
q
end
end
+
+ def escape_like(field)
+ field.gsub(/[_%]/) { |x| "\\#{x}" }
+ end
+
end