summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-11-26 23:04:22 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2018-11-30 03:57:05 +0000
commit7b90034acd5aca95c0195eba58cf5cb47d0e53f3 (patch)
treed1027a2fe729f758ae7744a70d4ccdfba557c999
parentb204e93e04fb16b2d9f0df465f86abab3706328d (diff)
downloadgitlab-ce-7b90034acd5aca95c0195eba58cf5cb47d0e53f3.tar.gz
Merge branch 'sh-fix-hash-filename-handling' into 'master'
Fix handling of filenames with hash characters in tree view Closes #54473 See merge request gitlab-org/gitlab-ce!23368 (cherry picked from commit 5d82035f623fd910c010c30b97112c46218430d4) e8da70e6 Fix handling of filenames with hash characters in tree view
-rw-r--r--app/helpers/tree_helper.rb4
-rw-r--r--changelogs/unreleased/sh-fix-hash-filename-handling.yml5
-rw-r--r--spec/helpers/tree_helper_spec.rb28
3 files changed, 35 insertions, 2 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index 78a11616d4c..e2879bfdcf1 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -37,13 +37,13 @@ module TreeHelper
# Using Rails `*_path` methods can be slow, especially when generating
# many paths, as with a repository tree that has thousands of items.
def fast_project_blob_path(project, blob_path)
- Addressable::URI.escape(
+ ActionDispatch::Journey::Router::Utils.escape_path(
File.join(relative_url_root, project.path_with_namespace, 'blob', blob_path)
)
end
def fast_project_tree_path(project, tree_path)
- Addressable::URI.escape(
+ ActionDispatch::Journey::Router::Utils.escape_path(
File.join(relative_url_root, project.path_with_namespace, 'tree', tree_path)
)
end
diff --git a/changelogs/unreleased/sh-fix-hash-filename-handling.yml b/changelogs/unreleased/sh-fix-hash-filename-handling.yml
new file mode 100644
index 00000000000..cb32051a4ab
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-hash-filename-handling.yml
@@ -0,0 +1,5 @@
+---
+title: Fix handling of filenames with hash characters in tree view
+merge_request: 23368
+author:
+type: fixed
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index ab4566e261b..4a62e696cd9 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -5,6 +5,16 @@ describe TreeHelper do
let(:repository) { project.repository }
let(:sha) { 'c1c67abbaf91f624347bb3ae96eabe3a1b742478' }
+ def create_file(filename)
+ project.repository.create_file(
+ project.creator,
+ filename,
+ 'test this',
+ message: "Automatically created file #{filename}",
+ branch_name: 'master'
+ )
+ end
+
describe '.render_tree' do
before do
@id = sha
@@ -57,6 +67,15 @@ describe TreeHelper do
expect(fast_path).to start_with('/gitlab/root')
end
+
+ it 'encodes files starting with #' do
+ filename = '#test-file'
+ create_file(filename)
+
+ fast_path = fast_project_blob_path(project, filename)
+
+ expect(fast_path).to end_with('%23test-file')
+ end
end
describe '.fast_project_tree_path' do
@@ -73,6 +92,15 @@ describe TreeHelper do
expect(fast_path).to start_with('/gitlab/root')
end
+
+ it 'encodes files starting with #' do
+ filename = '#test-file'
+ create_file(filename)
+
+ fast_path = fast_project_tree_path(project, filename)
+
+ expect(fast_path).to end_with('%23test-file')
+ end
end
describe 'flatten_tree' do