diff options
-rw-r--r-- | app/helpers/tree_helper.rb | 4 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-hash-filename-handling.yml | 5 | ||||
-rw-r--r-- | spec/helpers/tree_helper_spec.rb | 28 |
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 |