From ad044f85d39ff944fc7884fa0ac7758fe296ecf1 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 19 Feb 2017 09:34:59 -0500 Subject: [PATCH] Fix keyword search in Firefox and URL search via query param Fixes #577. --- lib/app.rb | 1 + test/app_test.rb | 6 ++++++ views/app.erb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/app.rb b/lib/app.rb index 11a2af44..0c785fc1 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -229,6 +229,7 @@ class App < Sinatra::Application end get '/' do + return redirect "/#q=#{params[:q]}" if params[:q] return redirect '/' unless request.query_string.empty? # courtesy of HTML5 App Cache response.headers['Content-Security-Policy'] = settings.csp if settings.csp erb :index diff --git a/test/app_test.rb b/test/app_test.rb index 448f6372..68e8f9d3 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -17,6 +17,12 @@ class AppTest < MiniTest::Spec assert last_response.ok? end + it "redirects to /#q= when there is a 'q' query param" do + get '/search', q: 'foo' + assert last_response.redirect? + assert_equal 'http://example.org/#q=foo', last_response['Location'] + end + it "redirects without the query string" do get '/', foo: 'bar' assert last_response.redirect? diff --git a/views/app.erb b/views/app.erb index 9ad9494d..ea98de63 100644 --- a/views/app.erb +++ b/views/app.erb @@ -5,7 +5,7 @@