Fix binary encoding error on MR diffs
This commit is contained in:
parent
b9fcc48aef
commit
6b53add3f9
3 changed files with 16 additions and 1 deletions
4
changelogs/unreleased/fix-encoding-binary-issue.yml
Normal file
4
changelogs/unreleased/fix-encoding-binary-issue.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Fix binary encoding error on MR diffs
|
||||||
|
merge_request: 11929
|
||||||
|
author:
|
|
@ -38,7 +38,7 @@ module Gitlab
|
||||||
|
|
||||||
def encode_utf8(message)
|
def encode_utf8(message)
|
||||||
detect = CharlockHolmes::EncodingDetector.detect(message)
|
detect = CharlockHolmes::EncodingDetector.detect(message)
|
||||||
if detect
|
if detect && detect[:encoding]
|
||||||
begin
|
begin
|
||||||
CharlockHolmes::Converter.convert(message, detect[:encoding], 'UTF-8')
|
CharlockHolmes::Converter.convert(message, detect[:encoding], 'UTF-8')
|
||||||
rescue ArgumentError => e
|
rescue ArgumentError => e
|
||||||
|
|
|
@ -139,4 +139,15 @@ describe MergeRequestDiff, models: true do
|
||||||
expect(subject.commits_count).to eq 2
|
expect(subject.commits_count).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#utf8_st_diffs' do
|
||||||
|
it 'does not raise error when a hash value is in binary' do
|
||||||
|
subject.st_diffs = [
|
||||||
|
{ diff: "\0" },
|
||||||
|
{ diff: "\x05\x00\x68\x65\x6c\x6c\x6f" }
|
||||||
|
]
|
||||||
|
|
||||||
|
expect { subject.utf8_st_diffs }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue