diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-30 08:41:49 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-08-30 08:41:49 +0000 |
commit | 8479b3b6fc051c3bd31330403e202ec5c09808f0 (patch) | |
tree | 106e68cc2cbafb509bcf6b0b206008fcb8655dda | |
parent | f981d4febbbb5103262f4daa858236d9c4ed9d67 (diff) | |
parent | fda12a61d35935ee852349ffa152fbcc724c14ae (diff) | |
download | gitlab-ce-8479b3b6fc051c3bd31330403e202ec5c09808f0.tar.gz |
Merge branch 'sh-fix-error-500-updating-wikis' into 'master'
Fix Error 500s due to encoding issues when Wiki hooks fire
Closes #50590
See merge request gitlab-org/gitlab-ce!21414
-rw-r--r-- | changelogs/unreleased/sh-fix-error-500-updating-wikis.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/encoding_helper.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/encoding_helper_spec.rb | 12 |
3 files changed, 18 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-error-500-updating-wikis.yml b/changelogs/unreleased/sh-fix-error-500-updating-wikis.yml new file mode 100644 index 00000000000..d80d4952ba5 --- /dev/null +++ b/changelogs/unreleased/sh-fix-error-500-updating-wikis.yml @@ -0,0 +1,5 @@ +--- +title: Fix Error 500s due to encoding issues when Wiki hooks fire +merge_request: 21414 +author: +type: fixed diff --git a/lib/gitlab/encoding_helper.rb b/lib/gitlab/encoding_helper.rb index d1fd5dfe0cb..0f336fbaa10 100644 --- a/lib/gitlab/encoding_helper.rb +++ b/lib/gitlab/encoding_helper.rb @@ -75,7 +75,7 @@ module Gitlab end def binary_stringio(str) - StringIO.new(str || '').tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } + StringIO.new(str.freeze || '').tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } end private diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb index e68c9850f6b..a5bf2f2b3df 100644 --- a/spec/lib/gitlab/encoding_helper_spec.rb +++ b/spec/lib/gitlab/encoding_helper_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require "spec_helper" describe Gitlab::EncodingHelper do @@ -187,4 +188,15 @@ describe Gitlab::EncodingHelper do end end end + + describe '#binary_stringio' do + it 'does not mutate the original string encoding' do + test = 'my-test' + + io_stream = ext_class.binary_stringio(test) + + expect(io_stream.external_encoding.name).to eq('ASCII-8BIT') + expect(test.encoding.name).to eq('UTF-8') + end + end end |