summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliot <ewiltshire@perforce.com>2016-08-11 13:15:46 +0200
committerRémy Coutable <remy@rymai.me>2016-08-11 13:21:59 +0200
commit68cea38e94886e69099a3faa0d1e2fbde2e71899 (patch)
tree417de4d96338cc4eff64607376992326dfabc64e
parent3a46eac1ef903c027c244d31369329f45c636914 (diff)
downloadgitlab-ce-10772-fix-urlencoded-branchname.tar.gz
Fix front-end for branches that happen to contain urlencoding escape characters (e.g. %)10772-fix-urlencoded-branchname
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--CHANGELOG1
-rw-r--r--lib/extracts_path.rb2
-rw-r--r--spec/lib/extracts_path_spec.rb19
3 files changed, 18 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3b567d9ec2c..8fb2194f612 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ v 8.11.0 (unreleased)
- Fix rename `add_users_into_project` and `projects_ids`. !20512 (herminiotorres)
- Fix the title of the toggle dropdown button. !5515 (herminiotorres)
- Improve diff performance by eliminating redundant checks for text blobs
+ - Ensure that branch names containing escapable characters (e.g. %20) aren't unescaped indiscriminately. !5770 (ewiltshi)
- Convert switch icon into icon font (ClemMakesApps)
- API: Endpoints for enabling and disabling deploy keys
- Use long options for curl examples in documentation !5703 (winniehell)
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 51e46da82cc..84688f6646e 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -94,7 +94,7 @@ module ExtractsPath
@options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
@options = HashWithIndifferentAccess.new(@options)
- @id = Addressable::URI.unescape(get_id)
+ @id = Addressable::URI.normalize_component(get_id)
@ref, @path = extract_ref(@id)
@repo = @project.repository
if @options[:extended_sha1].blank?
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index b12a7b98d4d..36c77206a3f 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -30,15 +30,28 @@ describe ExtractsPath, lib: true do
expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb")
end
- context 'escaped sequences in ref' do
- let(:ref) { "improve%2Fawesome" }
+ context 'escaped slash character in ref' do
+ let(:ref) { 'improve%2Fawesome' }
- it "id has no escape sequences" do
+ it 'has no escape sequences in @ref or @logs_path' do
assign_ref_vars
+
expect(@ref).to eq('improve/awesome')
expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb")
end
end
+
+ context 'ref contains %20' do
+ let(:ref) { 'foo%20bar' }
+
+ it 'is not converted to a space in @id' do
+ @project.repository.add_branch(@project.owner, 'foo%20bar', 'master')
+
+ assign_ref_vars
+
+ expect(@id).to start_with('foo%20bar/')
+ end
+ end
end
describe '#extract_ref' do