Commit 7142af49 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch '40230-groups-gitlab-org-labels-json-redirects-to-groups-gitlab-org-labels-json' into 'master'

Resolve "/groups/gitlab-org/labels.json redirects to /groups/gitlab-org/-/labels/.json"

Closes #40230

See merge request gitlab-org/gitlab-ce!15427
parents e68ee8af 9f921b73
...@@ -46,10 +46,10 @@ module Gitlab ...@@ -46,10 +46,10 @@ module Gitlab
# Only replace the last occurence of `path`. # Only replace the last occurence of `path`.
# #
# `request.fullpath` includes the querystring # `request.fullpath` includes the querystring
path = request.path.sub(%r{/#{path}/*(?!.*#{path})}, "/-/#{path}/") new_path = request.path.sub(%r{/#{path}(/*)(?!.*#{path})}, "/-/#{path}\\1")
path << "?#{request.query_string}" if request.query_string.present? new_path << "?#{request.query_string}" if request.query_string.present?
path new_path
end end
paths.each do |path| paths.each do |path|
......
...@@ -39,13 +39,19 @@ describe "Groups", "routing" do ...@@ -39,13 +39,19 @@ describe "Groups", "routing" do
describe 'legacy redirection' do describe 'legacy redirection' do
describe 'labels' do describe 'labels' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/labels", "/groups/complex.group-namegit/-/labels/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/labels", "/groups/complex.group-namegit/-/labels" do
let(:resource) { create(:group, parent: group, path: 'labels') } let(:resource) { create(:group, parent: group, path: 'labels') }
end end
context 'when requesting JSON' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/labels.json", "/groups/complex.group-namegit/-/labels.json" do
let(:resource) { create(:group, parent: group, path: 'labels') }
end
end
end end
describe 'group_members' do describe 'group_members' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/group_members", "/groups/complex.group-namegit/-/group_members/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/group_members", "/groups/complex.group-namegit/-/group_members" do
let(:resource) { create(:group, parent: group, path: 'group_members') } let(:resource) { create(:group, parent: group, path: 'group_members') }
end end
end end
...@@ -60,7 +66,7 @@ describe "Groups", "routing" do ...@@ -60,7 +66,7 @@ describe "Groups", "routing" do
end end
describe 'milestones' do describe 'milestones' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones", "/groups/complex.group-namegit/-/milestones/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones", "/groups/complex.group-namegit/-/milestones" do
let(:resource) { create(:group, parent: group, path: 'milestones') } let(:resource) { create(:group, parent: group, path: 'milestones') }
end end
...@@ -76,18 +82,18 @@ describe "Groups", "routing" do ...@@ -76,18 +82,18 @@ describe "Groups", "routing" do
end end
context 'with a query string' do 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 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') } let(:resource) { create(:group, parent: group, path: 'milestones') }
end end
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/milestones?milestones=/milestones", "/groups/complex.group-namegit/-/milestones/?milestones=/milestones" do 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') } let(:resource) { create(:group, parent: group, path: 'milestones') }
end end
end end
end end
describe 'edit' do describe 'edit' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/edit", "/groups/complex.group-namegit/-/edit/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/edit", "/groups/complex.group-namegit/-/edit" do
let(:resource) do let(:resource) do
pending('still rejected because of the wildcard reserved word') pending('still rejected because of the wildcard reserved word')
create(:group, parent: group, path: 'edit') create(:group, parent: group, path: 'edit')
...@@ -96,29 +102,29 @@ describe "Groups", "routing" do ...@@ -96,29 +102,29 @@ describe "Groups", "routing" do
end end
describe 'issues' do describe 'issues' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/issues", "/groups/complex.group-namegit/-/issues/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/issues", "/groups/complex.group-namegit/-/issues" do
let(:resource) { create(:group, parent: group, path: 'issues') } let(:resource) { create(:group, parent: group, path: 'issues') }
end end
end end
describe 'merge_requests' do describe 'merge_requests' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/merge_requests", "/groups/complex.group-namegit/-/merge_requests/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/merge_requests", "/groups/complex.group-namegit/-/merge_requests" do
let(:resource) { create(:group, parent: group, path: 'merge_requests') } let(:resource) { create(:group, parent: group, path: 'merge_requests') }
end end
end end
describe 'projects' do describe 'projects' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/projects", "/groups/complex.group-namegit/-/projects/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/projects", "/groups/complex.group-namegit/-/projects" do
let(:resource) { create(:group, parent: group, path: 'projects') } let(:resource) { create(:group, parent: group, path: 'projects') }
end end
end end
describe 'activity' do describe 'activity' do
it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/activity", "/groups/complex.group-namegit/-/activity/" do it_behaves_like 'redirecting a legacy path', "/groups/complex.group-namegit/activity", "/groups/complex.group-namegit/-/activity" do
let(:resource) { create(:group, parent: group, path: 'activity') } let(:resource) { create(:group, parent: group, path: 'activity') }
end end
it_behaves_like 'redirecting a legacy path', "/groups/activity/activity", "/groups/activity/-/activity/" do it_behaves_like 'redirecting a legacy path', "/groups/activity/activity", "/groups/activity/-/activity" do
let!(:parent) { create(:group, path: 'activity') } let!(:parent) { create(:group, path: 'activity') }
let(:resource) { create(:group, parent: parent, path: 'activity') } let(:resource) { create(:group, parent: parent, path: 'activity') }
end end
......
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