Resolve "Error 500 in non-UTF8 branch names"
This commit is contained in:
parent
30db01b2ed
commit
a31e0aff22
5 changed files with 30 additions and 2 deletions
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Fixed non-UTF-8 valid branch names from causing an error.
|
||||
merge_request: 14090
|
||||
type: fixed
|
|
@ -11,7 +11,7 @@ module Gitlab
|
|||
include Gitlab::EncodingHelper
|
||||
|
||||
def ref_name(ref)
|
||||
encode! ref.sub(/\Arefs\/(tags|heads|remotes)\//, '')
|
||||
encode_utf8(ref).sub(/\Arefs\/(tags|heads|remotes)\//, '')
|
||||
end
|
||||
|
||||
def branch_name(ref)
|
||||
|
|
|
@ -367,5 +367,20 @@ describe Projects::BranchesController do
|
|||
expect(parsed_response.first).to eq 'master'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when branch contains an invalid UTF-8 sequence' do
|
||||
before do
|
||||
project.repository.create_branch("wrong-\xE5-utf8-sequence")
|
||||
end
|
||||
|
||||
it 'return with a status 200' do
|
||||
get :index,
|
||||
namespace_id: project.namespace,
|
||||
project_id: project,
|
||||
format: :html
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ describe Gitlab::DataBuilder::Push do
|
|||
include_examples 'deprecated repository hook data'
|
||||
|
||||
it 'does not raise an error when given nil commits' do
|
||||
expect { described_class.build(spy, spy, spy, spy, spy, nil) }
|
||||
expect { described_class.build(spy, spy, spy, spy, 'refs/tags/v1.1.0', nil) }
|
||||
.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# coding: utf-8
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Git do
|
||||
|
@ -29,4 +30,12 @@ describe Gitlab::Git do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.ref_name' do
|
||||
it 'ensure ref is a valid UTF-8 string' do
|
||||
utf8_invalid_ref = Gitlab::Git::BRANCH_REF_PREFIX + "an_invalid_ref_\xE5"
|
||||
|
||||
expect(described_class.ref_name(utf8_invalid_ref)).to eq("an_invalid_ref_å")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue