Commit 27cc1c2b authored by Andrew Newdigate's avatar Andrew Newdigate Committed by Sean McGivern

Fix for Gitaly nil encoding issue

parent d14230dd
......@@ -233,6 +233,8 @@ module Gitlab
end
def self.encode(s)
return "" if s.nil?
s.dup.force_encoding(Encoding::ASCII_8BIT)
end
......
......@@ -274,7 +274,7 @@ module Gitlab
repository: @gitaly_repo,
left_commit_id: from_id,
right_commit_id: to_id,
paths: options.fetch(:paths, []).map { |path| GitalyClient.encode(path) }
paths: options.fetch(:paths, []).compact.map { |path| GitalyClient.encode(path) }
}
end
......
......@@ -53,7 +53,7 @@ describe Gitlab::GitalyClient::CommitService do
end
it 'encodes paths correctly' do
expect { client.diff_from_parent(commit, paths: ['encoding/test.txt', 'encoding/テスト.txt']) }.not_to raise_error
expect { client.diff_from_parent(commit, paths: ['encoding/test.txt', 'encoding/テスト.txt', nil]) }.not_to raise_error
end
end
......
......@@ -38,6 +38,20 @@ describe Gitlab::GitalyClient, skip_gitaly_mock: true do
end
end
describe 'encode' do
[
[nil, ""],
["", ""],
[" ", " "],
%w(a1 a1),
["编码", "\xE7\xBC\x96\xE7\xA0\x81".b]
].each do |input, result|
it "encodes #{input.inspect} to #{result.inspect}" do
expect(described_class.encode(input)).to eq result
end
end
end
describe 'allow_n_plus_1_calls' do
context 'when RequestStore is enabled', :request_store do
it 'returns the result of the allow_n_plus_1_calls block' 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