diff --git a/lib/devise/controllers/store_location.rb b/lib/devise/controllers/store_location.rb index a701d34f..b249037a 100644 --- a/lib/devise/controllers/store_location.rb +++ b/lib/devise/controllers/store_location.rb @@ -33,7 +33,10 @@ module Devise # def store_location_for(resource_or_scope, location) session_key = stored_location_key_for(resource_or_scope) - session[session_key] = URI.parse(location).path.sub(/\A\/+/, '/') if location + if location + uri = URI.parse(location) + session[session_key] = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?') + end end private diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 0238ba1a..3abd0e19 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -198,13 +198,18 @@ class ControllerAuthenticatableTest < ActionController::TestCase assert_equal "/foo.bar", @controller.stored_location_for(User.new) end - test 'store location for stores only paths' do + test 'store location for stores paths' do @controller.store_location_for(:user, "//host/foo.bar") assert_equal "/foo.bar", @controller.stored_location_for(:user) @controller.store_location_for(:user, "///foo.bar") assert_equal "/foo.bar", @controller.stored_location_for(:user) end + test 'store location for stores query string' do + @controller.store_location_for(:user, "/foo?bar=baz") + assert_equal "/foo?bar=baz", @controller.stored_location_for(:user) + end + test 'after sign in path defaults to root path if none by was specified for the given scope' do assert_equal root_path, @controller.after_sign_in_path_for(:user) end