summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-04-04 18:09:09 +0000
committerRobert Speicher <robert@gitlab.com>2018-04-04 18:09:09 +0000
commitcb5bb4dbc67c5dd43bb7b27faf79ca79f8ae3e1f (patch)
treec1ad1f65b479b2a7a87ec72d22a243babee074de
parentd5d7bcf8b7404a436c577e2b112aa59dc2901378 (diff)
parent097636575c7d1e85b16e4c4eb7d87ce74137d64f (diff)
downloadgitlab-ce-cb5bb4dbc67c5dd43bb7b27faf79ca79f8ae3e1f.tar.gz
Merge branch 'dm-flatten-tree-plus-chars' into 'master'
Fix links to subdirectories of a directory with a plus character in its path Closes #44967 See merge request gitlab-org/gitlab-ce!18172
-rw-r--r--app/helpers/tree_helper.rb2
-rw-r--r--changelogs/unreleased/dm-flatten-tree-plus-chars.yml5
-rw-r--r--spec/helpers/tree_helper_spec.rb10
3 files changed, 16 insertions, 1 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index b64be89c181..5e7c20ef51e 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -123,7 +123,7 @@ module TreeHelper
# returns the relative path of the first subdir that doesn't have only one directory descendant
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)
if subtree.count == 1 && subtree.first.dir?
diff --git a/changelogs/unreleased/dm-flatten-tree-plus-chars.yml b/changelogs/unreleased/dm-flatten-tree-plus-chars.yml
new file mode 100644
index 00000000000..23f1b30d8fa
--- /dev/null
+++ b/changelogs/unreleased/dm-flatten-tree-plus-chars.yml
@@ -0,0 +1,5 @@
+---
+title: Fix links to subdirectories of a directory with a plus character in its path
+merge_request:
+author:
+type: fixed
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index ccac6e29447..ffdf6561a53 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -8,6 +8,7 @@ describe TreeHelper do
describe '.render_tree' do
before do
@id = sha
+ @path = ""
@project = project
@lfs_blob_ids = []
end
@@ -61,6 +62,15 @@ describe TreeHelper do
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
describe '#commit_in_single_accessible_branch' do