Skip to content
Snippets Groups Projects
Commit 038be9ff authored by Stan Hu's avatar Stan Hu
Browse files

Fix Error 500s due to encoding issues when Wiki hooks fire

Saved Wiki content goes through the GitalyClient::WikiService, which calls
StringIO#set_encoding on the input stream. The problem is that this call
mutates the encoding of the given string object to ASCII-88BIT, which
causes problems for models expecting the data to still be in UTF-8.

Freezing the input disables this behavior:
https://github.com/ruby/ruby/blob/v2_4_4/ext/stringio/stringio.c#L1583

Closes #50590
parent 42523a41
No related branches found
No related tags found
No related merge requests found
---
title: Fix Error 500s due to encoding issues when Wiki hooks fire
merge_request:
author:
type: fixed
Loading
Loading
@@ -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
Loading
Loading
# coding: utf-8
require "spec_helper"
 
describe Gitlab::EncodingHelper do
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment