BigW Consortium Gitlab

Commit 843f52ea by Sean McGivern Committed by Lin Jen-Shin

Merge branch 'fix/encoding-issue' into 'master'

Fix encoding issue exporting a project Closes #31186 See merge request !10824
parent 6b76909c
---
title: Fix encoding issue exporting a project
merge_request:
author:
...@@ -40,7 +40,13 @@ module Gitlab ...@@ -40,7 +40,13 @@ module Gitlab
def encode_utf8(message) def encode_utf8(message)
detect = CharlockHolmes::EncodingDetector.detect(message) detect = CharlockHolmes::EncodingDetector.detect(message)
if detect if detect
CharlockHolmes::Converter.convert(message, detect[:encoding], 'UTF-8') begin
CharlockHolmes::Converter.convert(message, detect[:encoding], 'UTF-8')
rescue ArgumentError => e
Rails.logger.warn("Ignoring error converting #{detect[:encoding]} into UTF8: #{e.message}")
''
end
else else
clean(message) clean(message)
end end
......
...@@ -56,6 +56,10 @@ describe Gitlab::Git::EncodingHelper do ...@@ -56,6 +56,10 @@ describe Gitlab::Git::EncodingHelper do
expect(r.encoding.name).to eq('UTF-8') expect(r.encoding.name).to eq('UTF-8')
end end
end end
it 'returns empty string on conversion errors' do
expect { ext_class.encode_utf8('') }.not_to raise_error(ArgumentError)
end
end end
describe '#clean' do describe '#clean' 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