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
This commit is contained in:
parent
42523a415d
commit
038be9fffa
3 changed files with 18 additions and 1 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix Error 500s due to encoding issues when Wiki hooks fire
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -75,7 +75,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def binary_stringio(str)
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# coding: utf-8
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
describe Gitlab::EncodingHelper do
|
describe Gitlab::EncodingHelper do
|
||||||
|
@ -187,4 +188,15 @@ describe Gitlab::EncodingHelper do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue