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 @@
module Constraints
class JiraEncodedUrlConstrainer
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
......@@ -3,26 +3,34 @@
require 'spec_helper'
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
using RSpec::Parameterized::TableSyntax
subject { described_class.new.matches?(request) }
where(:path, :match_result) do
"/-/jira/group/project" | true
"/-/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
context 'when there is no /-/jira prefix and no encoded slash' do
it { is_expected.to eq(false) }
end
with_them do
it 'matches path with /-/jira prefix or encoded slash' do
request = build_request(path)
context 'when tree path contains encoded slash' do
let(:path) { "/#{namespace_id}/#{project_id}/tree/folder-with-#{Gitlab::Jira::Dvcs::ENCODED_SLASH}" }
expect(subject.matches?(request)).to eq(match_result)
end
it { is_expected.to eq(false) }
end
end
def build_request(path)
double(:request, path: path)
context 'when path has /-/jira prefix' do
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
......@@ -59,4 +59,14 @@ describe 'Jira referenced paths', type: :request do
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
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