Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Kiesel <james.kiesel@gmail.com>2014-10-09 14:28:30 +0400
committerJames Kiesel <james.kiesel@gmail.com>2014-10-09 14:34:11 +0400
commit206ec99f8f8df0e2f8244b8539fe81f2b69384b4 (patch)
treee54315d06dea2655c335e1bede6795bebf6817c2
parentd44300c7a2b7bc8bd33ab880134695d0dc75d490 (diff)
Strip search query of leading & trailing whitespace
-rw-r--r--app/controllers/search_controller.rb2
-rw-r--r--spec/controllers/search_controller_spec.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 6c2f43474..f3a320615 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -20,7 +20,7 @@ class SearchController < ApplicationController
private
def search_query
- @search_query ||= params[:q] || params[:term] || ''
+ @search_query ||= (params[:q] || params[:term] || '').strip
end
end
diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb
index 5ec4baf6d..bc07db4ae 100644
--- a/spec/controllers/search_controller_spec.rb
+++ b/spec/controllers/search_controller_spec.rb
@@ -35,5 +35,16 @@ describe SearchController, :type => :controller do
end
end
+ describe '#search_query' do
+ it 'strips the term parameter' do
+ @controller.params[:term] = ' IN SPACE! '
+ expect(@controller.send(:search_query)).to eq 'IN SPACE!'
+ end
+
+ it 'strips the q parameter' do
+ @controller.params[:q] = ' IN SPACE! '
+ expect(@controller.send(:search_query)).to eq 'IN SPACE!'
+ end
+ end
end