Commit 2414c69e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Check redirecting with a querystring

parent e070e216
...@@ -44,8 +44,10 @@ module Gitlab ...@@ -44,8 +44,10 @@ module Gitlab
def self.redirect_legacy_paths(router, *paths) def self.redirect_legacy_paths(router, *paths)
build_redirect_path = lambda do |request, _params, path| build_redirect_path = lambda do |request, _params, path|
# Only replace the last occurence of `path`. # Only replace the last occurence of `path`.
path = request.fullpath.sub(%r{/#{path}/*(?!.*#{path})}, "/-/#{path}/") #
path << request.query_string if request.query_string.present? # `request.fullpath` includes the querystring
path = request.path.sub(%r{/#{path}/*(?!.*#{path})}, "/-/#{path}/")
path << "?#{request.query_string}" if request.query_string.present?
path path
end end
......
...@@ -74,6 +74,16 @@ describe "Groups", "routing" do ...@@ -74,6 +74,16 @@ describe "Groups", "routing" do
expect(request).to redirect_to("/groups/#{group_path}/-/milestones/#{milestone.id}/merge_requests") expect(request).to redirect_to("/groups/#{group_path}/-/milestones/#{milestone.id}/merge_requests")
end end
end end
context 'with a query string' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones?hello=world", "/groups/complex.group-namegit/-/milestones/?hello=world" do
let(:resource) { create(:group, parent: group, path: 'milestones') }
end
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones?milestones=/milestones", "/groups/complex.group-namegit/-/milestones/?milestones=/milestones" do
let(:resource) { create(:group, parent: group, path: 'milestones') }
end
end
end end
describe 'edit' do describe 'edit' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment