Fix links to subdirectories of a directory with a plus character in its path
This commit is contained in:
parent
eaed588bf2
commit
097636575c
|
@ -123,7 +123,7 @@ module TreeHelper
|
||||||
|
|
||||||
# returns the relative path of the first subdir that doesn't have only one directory descendant
|
# returns the relative path of the first subdir that doesn't have only one directory descendant
|
||||||
def flatten_tree(root_path, tree)
|
def flatten_tree(root_path, tree)
|
||||||
return tree.flat_path.sub(%r{\A#{root_path}/}, '') if tree.flat_path.present?
|
return tree.flat_path.sub(%r{\A#{Regexp.escape(root_path)}/}, '') if tree.flat_path.present?
|
||||||
|
|
||||||
subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
|
subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
|
||||||
if subtree.count == 1 && subtree.first.dir?
|
if subtree.count == 1 && subtree.first.dir?
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix links to subdirectories of a directory with a plus character in its path
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -8,6 +8,7 @@ describe TreeHelper do
|
||||||
describe '.render_tree' do
|
describe '.render_tree' do
|
||||||
before do
|
before do
|
||||||
@id = sha
|
@id = sha
|
||||||
|
@path = ""
|
||||||
@project = project
|
@project = project
|
||||||
@lfs_blob_ids = []
|
@lfs_blob_ids = []
|
||||||
end
|
end
|
||||||
|
@ -61,6 +62,15 @@ describe TreeHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the root path contains a plus character' do
|
||||||
|
let(:root_path) { 'gtk/C++' }
|
||||||
|
let(:tree_item) { double(flat_path: 'gtk/C++/glade') }
|
||||||
|
|
||||||
|
it 'returns the flattened path' do
|
||||||
|
expect(subject).to eq('glade')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#commit_in_single_accessible_branch' do
|
describe '#commit_in_single_accessible_branch' do
|
||||||
|
|
Loading…
Reference in New Issue