Commit 75f257ad authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-for-nil-encoding-issue' into 'master'

Fix for Gitaly nil encoding issue

See merge request gitlab-org/gitlab-ce!14581
parents d14230dd 27cc1c2b
...@@ -233,6 +233,8 @@ module Gitlab ...@@ -233,6 +233,8 @@ module Gitlab
end end
def self.encode(s) def self.encode(s)
return "" if s.nil?
s.dup.force_encoding(Encoding::ASCII_8BIT) s.dup.force_encoding(Encoding::ASCII_8BIT)
end end
......
...@@ -274,7 +274,7 @@ module Gitlab ...@@ -274,7 +274,7 @@ module Gitlab
repository: @gitaly_repo, repository: @gitaly_repo,
left_commit_id: from_id, left_commit_id: from_id,
right_commit_id: to_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 end
......
...@@ -53,7 +53,7 @@ describe Gitlab::GitalyClient::CommitService do ...@@ -53,7 +53,7 @@ describe Gitlab::GitalyClient::CommitService do
end end
it 'encodes paths correctly' do 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
end end
......
...@@ -38,6 +38,20 @@ describe Gitlab::GitalyClient, skip_gitaly_mock: true do ...@@ -38,6 +38,20 @@ describe Gitlab::GitalyClient, skip_gitaly_mock: true do
end end
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 describe 'allow_n_plus_1_calls' do
context 'when RequestStore is enabled', :request_store do context 'when RequestStore is enabled', :request_store do
it 'returns the result of the allow_n_plus_1_calls block' 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