Commit 95268679 authored by Michael Kozono's avatar Michael Kozono

Merge branch '37419-fix-redirect-loop-for-folders-with-at-sign' into 'master'

Fix redirect loop when navigating folders with @

See merge request gitlab-org/gitlab!21393
parents 56359ff8 1b310703
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Constraints module Constraints
class JiraEncodedUrlConstrainer class JiraEncodedUrlConstrainer
def matches?(request) def matches?(request)
request.path.starts_with?('/-/jira') || request.path.include?(Gitlab::Jira::Dvcs::ENCODED_SLASH) request.path.starts_with?('/-/jira') || request.params[:project_id].include?(Gitlab::Jira::Dvcs::ENCODED_SLASH)
end end
end end
end end
...@@ -3,26 +3,34 @@ ...@@ -3,26 +3,34 @@
require 'spec_helper' require 'spec_helper'
describe Constraints::JiraEncodedUrlConstrainer do describe Constraints::JiraEncodedUrlConstrainer do
let(:namespace_id) { 'group' }
let(:project_id) { 'project' }
let(:path) { "/#{namespace_id}/#{project_id}" }
let(:request) { double(:request, path: path, params: { namespace_id: namespace_id, project_id: project_id }) }
describe '#matches?' do describe '#matches?' do
using RSpec::Parameterized::TableSyntax subject { described_class.new.matches?(request) }
where(:path, :match_result) do context 'when there is no /-/jira prefix and no encoded slash' do
"/-/jira/group/project" | true it { is_expected.to eq(false) }
"/-/jira/group/sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" | true
"/group/sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" | true
"/group/project" | false
end end
with_them do context 'when tree path contains encoded slash' do
it 'matches path with /-/jira prefix or encoded slash' do let(:path) { "/#{namespace_id}/#{project_id}/tree/folder-with-#{Gitlab::Jira::Dvcs::ENCODED_SLASH}" }
request = build_request(path)
expect(subject.matches?(request)).to eq(match_result) it { is_expected.to eq(false) }
end
end end
end
def build_request(path) context 'when path has /-/jira prefix' do
double(:request, path: path) let(:path) { "/-/jira/#{namespace_id}/#{project_id}" }
it { is_expected.to eq(true) }
end
context 'when project_id has encoded slash' do
let(:project_id) { "sub_group#{Gitlab::Jira::Dvcs::ENCODED_SLASH}sub_project" }
it { is_expected.to eq(true) }
end
end end
end end
...@@ -59,4 +59,14 @@ describe 'Jira referenced paths', type: :request do ...@@ -59,4 +59,14 @@ describe 'Jira referenced paths', type: :request do
end end
end end
end end
context 'when tree path has an @' do
let(:path) { '/group/project/tree/folder-with-@' }
it 'does not do a redirect' do
get path
expect(response).not_to have_gitlab_http_status(:moved_permanently)
end
end
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