Commit 553f830e authored by Sean McGivern's avatar Sean McGivern

Merge branch '240921-fix-merge-request-diff-file-invalid-base64' into 'master'

Fall back to the raw diff if base64 encoding fails

Closes #240921

See merge request gitlab-org/gitlab!40598
parents 2288463a e9ac3df7
......@@ -25,6 +25,16 @@ class MergeRequestDiffFile < ApplicationRecord
super
end
binary? ? content.unpack1('m0') : content
return content unless binary?
# If the data isn't valid base64, return it as-is, since it's almost certain
# to be a valid diff. Parsing it as a diff will fail if it's something else.
#
# https://gitlab.com/gitlab-org/gitlab/-/issues/240921
begin
content.unpack1('m0')
rescue ArgumentError
content
end
end
end
---
title: Fix reading some merge request diffs
merge_request: 40598
author:
type: fixed
......@@ -25,6 +25,14 @@ RSpec.describe MergeRequestDiffFile do
it 'unpacks from base 64' do
expect(subject.diff).to eq(unpacked)
end
context 'invalid base64' do
let(:packed) { '---/dev/null' }
it 'returns the raw diff' do
expect(subject.diff).to eq(packed)
end
end
end
context 'when the diff is not marked as binary' 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