Commit a31e0aff authored by Micael Bergeron's avatar Micael Bergeron Committed by Rémy Coutable

Resolve "Error 500 in non-UTF8 branch names"

parent 30db01b2
---
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
......
# 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
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