From 396b8f91ec47ffb5a02ebf6d713ef4cbf04f1f94 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 25 Jul 2017 17:57:02 +0100 Subject: Fix saving diffs that are not valid UTF-8 Previously, we used Psych, which would: 1. Check if a string was encoded as binary, and not ASCII-compatible. 2. Add the !binary tag in that case. 3. Convert to base64. We need to do the same thing, using a new column in place of the tag. --- app/models/merge_request_diff_file.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/models/merge_request_diff_file.rb') diff --git a/app/models/merge_request_diff_file.rb b/app/models/merge_request_diff_file.rb index 598ebd4d829..1199ff5af22 100644 --- a/app/models/merge_request_diff_file.rb +++ b/app/models/merge_request_diff_file.rb @@ -8,4 +8,14 @@ class MergeRequestDiffFile < ActiveRecord::Base encode_utf8(diff) if diff.respond_to?(:encoding) end + + def diff + binary? ? super.unpack('m0').first : super + end + + def to_hash + keys = Gitlab::Git::Diff::SERIALIZE_KEYS - [:diff] + + as_json(only: keys).merge(diff: diff).with_indifferent_access + end end -- cgit v1.2.1