Commit 826d5b7b authored by Robert Speicher's avatar Robert Speicher

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

Encode Gitaly diff patches properly

See merge request !12368
parents 8fe5602c 5b092d21
...@@ -318,7 +318,7 @@ module Gitlab ...@@ -318,7 +318,7 @@ module Gitlab
end end
def init_from_gitaly(diff) 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) @new_path = encode!(diff.to_path.dup)
@old_path = encode!(diff.from_path.dup) @old_path = encode!(diff.from_path.dup)
@a_mode = diff.old_mode.to_s(8) @a_mode = diff.old_mode.to_s(8)
......
...@@ -13,7 +13,10 @@ module Gitlab ...@@ -13,7 +13,10 @@ module Gitlab
@rpc_response.each do |diff_msg| @rpc_response.each do |diff_msg|
if current_diff.nil? if current_diff.nil?
diff_params = diff_msg.to_h.slice(*GitalyClient::Diff::FIELDS) 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) current_diff = GitalyClient::Diff.new(diff_params)
else else
......
...@@ -175,6 +175,14 @@ EOT ...@@ -175,6 +175,14 @@ EOT
expect(diff).to be_too_large expect(diff).to be_too_large
end end
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
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