Commit e9304e7b authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'fix-encoding-for-nil-diff-files' into 'master'

Fix encoding detection for nil diffs

See merge request gitlab-org/gitlab!42825
parents a11a84ec ca4ba45b
......@@ -509,6 +509,8 @@ class MergeRequestDiff < ApplicationRecord
end
def encode_in_base64?(diff_text)
return false if diff_text.nil?
(diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only?) ||
diff_text.include?("\0")
end
......@@ -536,7 +538,7 @@ class MergeRequestDiff < ApplicationRecord
rows.each do |row|
data = row.delete(:diff)
row[:external_diff_offset] = file.pos
row[:external_diff_size] = data.bytesize
row[:external_diff_size] = data&.bytesize || 0
file.write(data)
end
......
---
title: Fix migrating some empty diffs
merge_request: 42825
author:
type: fixed
......@@ -180,6 +180,17 @@ RSpec.describe MergeRequestDiff do
expect(diff.external_diff_store).to eq(file_store)
end
it 'migrates a nil diff file' do
expect(diff).not_to be_stored_externally
MergeRequestDiffFile.where(merge_request_diff_id: diff.id).update_all(diff: nil)
stub_external_diffs_setting(enabled: true)
diff.migrate_files_to_external_storage!
expect(diff).to be_stored_externally
end
it 'safely handles a transaction error when migrating to external storage' do
expect(diff).not_to be_stored_externally
expect(diff.external_diff).not_to be_exists
......
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