Fix double escape on Release Edit/Show paths
Problem
When you create Release with a tag name that contains a slash (/
), it produces a double-escaped path. For example,
The path should be releases/test%2Fv0.1
instead of releases/test%252Fv0.1
.
It seems rails route escape the param by default. I couldn't locate the exact place but seems it does. The double escape comes from !17858 (diffs).
Proposal
diff --git a/app/models/release.rb b/app/models/release.rb
index c6c0920c4d0..655a2ba4709 100644
--- a/app/models/release.rb
+++ b/app/models/release.rb
@@ -54,7 +54,7 @@ class Release < ApplicationRecord
MAX_NUMBER_TO_DISPLAY = 3
def to_param
- CGI.escape(tag)
+ tag
end
def commit
diff --git a/app/views/projects/tags/_tag.html.haml b/app/views/projects/tags/_tag.html.haml
index 0ee3b89b629..7654150509e 100644
--- a/app/views/projects/tags/_tag.html.haml
+++ b/app/views/projects/tags/_tag.html.haml
@@ -21,7 +21,7 @@
.text-secondary
= sprite_icon("rocket", size: 12)
= _("Release")
- = link_to release.name, project_releases_path(@project, anchor: release.tag), class: 'gl-text-blue-600!'
+ = link_to release.name, project_release_path(@project, release), class: 'gl-text-blue-600!'
- if tag.message.present?
%pre.wrap
diff --git a/config/routes/project.rb b/config/routes/project.rb
index 6b2a9700686..c61e2fac730 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -227,7 +227,7 @@
end
end
- resources :releases, only: [:index, :new, :show, :edit], param: :tag, constraints: { tag: %r{[^/]+} } do
+ resources :releases, only: [:index, :new, :show, :edit], param: :tag do
member do
get :downloads, path: 'downloads/*filepath', format: false
scope module: :releases do
For example,
release = Release.last
project = release.project
Gitlab::Routing.url_helpers.project_release_url(project, release)
produces
=> "http://local.gitlab.test:8181/xyz-org1/awesome-project/-/releases/test%2Fv0.1"
which is expected param (escape once)
Though this might require a broader refactoring because we expect escaped param in some places (example). This should be a follow-up issue.
Edited by Shinya Maeda