Merge branch 'fix/properly-encode-gitaly-diffs' into 'master'

Encode Gitaly diff patches properly

See merge request !12368
This commit is contained in:
Robert Speicher 2017-06-22 16:50:30 +00:00
commit 826d5b7b51
3 changed files with 13 additions and 2 deletions

View file

@ -318,7 +318,7 @@ module Gitlab
end
def init_from_gitaly(diff)
@diff = diff.patch if diff.respond_to?(:patch)
@diff = encode!(diff.patch) if diff.respond_to?(:patch)
@new_path = encode!(diff.to_path.dup)
@old_path = encode!(diff.from_path.dup)
@a_mode = diff.old_mode.to_s(8)

View file

@ -13,7 +13,10 @@ module Gitlab
@rpc_response.each do |diff_msg|
if current_diff.nil?
diff_params = diff_msg.to_h.slice(*GitalyClient::Diff::FIELDS)
diff_params[:patch] = diff_msg.raw_patch_data
# gRPC uses frozen strings by default, and we need to have an unfrozen string as it
# gets processed further down the line. So we unfreeze the first chunk of the patch
# in case it's the only chunk we receive for this diff.
diff_params[:patch] = diff_msg.raw_patch_data.dup
current_diff = GitalyClient::Diff.new(diff_params)
else

View file

@ -175,6 +175,14 @@ EOT
expect(diff).to be_too_large
end
end
context 'when the patch passed is not UTF-8-encoded' do
let(:raw_patch) { @raw_diff_hash[:diff].encode(Encoding::ASCII_8BIT) }
it 'encodes diff patch to UTF-8' do
expect(diff.diff.encoding).to eq(Encoding::UTF_8)
end
end
end
end