Commit 863f6134 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-branch-errors-with-encoded-slashes' into 'master'

Fix errors deleting, creating, and viewing graphs using branches with encoded slashes

* Closes #1804
* Closes #1359

See merge request !1084
parents ce47dd4b ecbe119a
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased) v 7.14.0 (unreleased)
- Fix "Network" and "Graphs" pages for branches with encoded slashes (Stan Hu)
- Fix errors deleting and creating branches with encoded slashes (Stan Hu)
- Fix multi-line syntax highlighting (Stan Hu) - Fix multi-line syntax highlighting (Stan Hu)
- Fix network graph when branch name has single quotes (Stan Hu) - Fix network graph when branch name has single quotes (Stan Hu)
- Add "Confirm user" button in user admin page (Stan Hu) - Add "Confirm user" button in user admin page (Stan Hu)
......
...@@ -17,7 +17,9 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -17,7 +17,9 @@ class Projects::BranchesController < Projects::ApplicationController
def create def create
branch_name = sanitize(strip_tags(params[:branch_name])) branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name)
ref = sanitize(strip_tags(params[:ref])) ref = sanitize(strip_tags(params[:ref]))
ref = Addressable::URI.unescape(ref)
result = CreateBranchService.new(project, current_user). result = CreateBranchService.new(project, current_user).
execute(branch_name, ref) execute(branch_name, ref)
...@@ -32,9 +34,8 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -32,9 +34,8 @@ class Projects::BranchesController < Projects::ApplicationController
end end
def destroy def destroy
status = DeleteBranchService.new(project, current_user).execute(params[:id]) @branch_name = Addressable::URI.unescape(params[:id])
@branch_name = params[:id] status = DeleteBranchService.new(project, current_user).execute(@branch_name)
respond_to do |format| respond_to do |format|
format.html do format.html do
redirect_to namespace_project_branches_path(@project.namespace, redirect_to namespace_project_branches_path(@project.namespace,
......
...@@ -94,7 +94,7 @@ module ExtractsPath ...@@ -94,7 +94,7 @@ module ExtractsPath
@options = params.select {|key, value| allowed_options.include?(key) && !value.blank? } @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
@options = HashWithIndifferentAccess.new(@options) @options = HashWithIndifferentAccess.new(@options)
@id = get_id @id = Addressable::URI.unescape(get_id)
@ref, @path = extract_ref(@id) @ref, @path = extract_ref(@id)
@repo = @project.repository @repo = @project.repository
if @options[:extended_sha1].blank? if @options[:extended_sha1].blank?
......
...@@ -54,6 +54,13 @@ describe Projects::BranchesController do ...@@ -54,6 +54,13 @@ describe Projects::BranchesController do
let(:ref) { "<script>alert('ref');</script>" } let(:ref) { "<script>alert('ref');</script>" }
it { is_expected.to render_template('new') } it { is_expected.to render_template('new') }
end end
context "valid branch name with encoded slashes" do
let(:branch) { "feature%2Ftest" }
let(:ref) { "<script>alert('ref');</script>" }
it { is_expected.to render_template('new') }
it { project.repository.branch_names.include?('feature/test')}
end
end end
describe "POST destroy" do describe "POST destroy" do
...@@ -74,6 +81,19 @@ describe Projects::BranchesController do ...@@ -74,6 +81,19 @@ describe Projects::BranchesController do
it { expect(subject).to render_template('destroy') } it { expect(subject).to render_template('destroy') }
end end
context "valid branch name with unencoded slashes" do
let(:branch) { "improve/awesome" }
it { expect(response.status).to eq(200) }
it { expect(subject).to render_template('destroy') }
end
context "valid branch name with encoded slashes" do
let(:branch) { "improve%2Fawesome" }
it { expect(response.status).to eq(200) }
it { expect(subject).to render_template('destroy') }
end
context "invalid branch name, valid ref" do context "invalid branch name, valid ref" do
let(:branch) { "no-branch" } let(:branch) { "no-branch" }
......
...@@ -29,6 +29,16 @@ describe ExtractsPath do ...@@ -29,6 +29,16 @@ describe ExtractsPath do
assign_ref_vars assign_ref_vars
expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb") expect(@logs_path).to eq("/#{@project.path_with_namespace}/refs/#{ref}/logs_tree/files/ruby/popen.rb")
end end
context 'escaped sequences in ref' do
let(:ref) { "improve%2Fawesome" }
it "id should have no escape sequences" 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
end end
describe '#extract_ref' do describe '#extract_ref' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment