diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-11-07 13:04:46 +0100 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-11-07 19:52:10 +0100 |
commit | 2414c69ee981cf6432e513dfdcf57a9badc5d51f (patch) | |
tree | 668a369dce88fd852d1601b8d5d223948d167071 | |
parent | e070e216c80efb897eb6c5a7d13872e4762205c1 (diff) | |
download | gitlab-ce-2414c69ee981cf6432e513dfdcf57a9badc5d51f.tar.gz |
Check redirecting with a querystring
-rw-r--r-- | lib/gitlab/routing.rb | 6 | ||||
-rw-r--r-- | spec/routing/group_routing_spec.rb | 10 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb index defb47663cb..910533076b0 100644 --- a/lib/gitlab/routing.rb +++ b/lib/gitlab/routing.rb @@ -44,8 +44,10 @@ module Gitlab def self.redirect_legacy_paths(router, *paths) build_redirect_path = lambda do |request, _params, 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 end diff --git a/spec/routing/group_routing_spec.rb b/spec/routing/group_routing_spec.rb index 3e56d34bc9d..7a4c8304e62 100644 --- a/spec/routing/group_routing_spec.rb +++ b/spec/routing/group_routing_spec.rb @@ -74,6 +74,16 @@ describe "Groups", "routing" do expect(request).to redirect_to("/groups/#{group_path}/-/milestones/#{milestone.id}/merge_requests") 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 describe 'edit' do |