diff options
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 2 | ||||
-rw-r--r-- | spec/controllers/search_controller_spec.rb | 11 |
3 files changed, 13 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index c46c92254..7f75719fb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -78,6 +78,7 @@ The keys will still be available in the root level within the 0.5 release. The o * Increase possible captcha length [#5169](https://github.com/diaspora/diaspora/pull/5169) * Display visibility icon in publisher aspects dropdown [#4982](https://github.com/diaspora/diaspora/pull/4982) * Add a link to the reported comment in the admin panel [#5337](https://github.com/diaspora/diaspora/pull/5337) +* Strip search query from leading and trailing whitespace [#5317](https://github.com/diaspora/diaspora/pull/5317) # 0.4.1.1 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 |