Fix redirection after login when the referer have params

This commit is contained in:
mhasbini 2017-04-02 18:54:19 +03:00
parent 9fc17f6f4a
commit af0c08b6f9
3 changed files with 21 additions and 1 deletions

View file

@ -79,7 +79,7 @@ class SessionsController < Devise::SessionsController
if request.referer.present? && (params['redirect_to_referer'] == 'yes')
referer_uri = URI(request.referer)
if referer_uri.host == Gitlab.config.gitlab.host
referer_uri.path
referer_uri.request_uri
else
request.fullpath
end

View file

@ -0,0 +1,4 @@
---
title: Fix redirection after login when the referer have params
merge_request:
author: mhasbini

View file

@ -211,4 +211,20 @@ describe SessionsController do
end
end
end
describe '#new' do
before do
@request.env['devise.mapping'] = Devise.mappings[:user]
end
it 'redirects correctly for referer on same host with params' do
search_path = '/search?search=seed_project'
allow(controller.request).to receive(:referer).
and_return('http://%{host}%{path}' % { host: Gitlab.config.gitlab.host, path: search_path })
get(:new, redirect_to_referer: :yes)
expect(controller.stored_location_for(:redirect)).to eq(search_path)
end
end
end