diff options
author | Kamil Trzciński (OoO till 16th of April) <ayufan@ayufan.eu> | 2018-04-18 11:25:53 +0300 |
---|---|---|
committer | Kamil Trzciński (OoO till 16th of April) <ayufan@ayufan.eu> | 2018-04-18 11:25:53 +0300 |
commit | df0a457d6f985da3b98aabb851390118254b1123 (patch) | |
tree | 0fc3153947b0852332721ff433d497fdb736918d /lib/gitlab/ci/trace | |
parent | 55ce9d244853a2534a80db3be4b9cfecb9625dd6 (diff) | |
parent | 1e14804da381ee594b8f7d26ba69a48fc6b3e9b8 (diff) |
Merge branch '44981-http-io-trace-with-multi-byte-char' into 'master'
Fix `Trace::HttpIO` can not render multi-byte chars
Closes #44981
See merge request gitlab-org/gitlab-ce!18417
Diffstat (limited to 'lib/gitlab/ci/trace')
-rw-r--r-- | lib/gitlab/ci/trace/http_io.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/gitlab/ci/trace/http_io.rb b/lib/gitlab/ci/trace/http_io.rb index ac4308f4e2c..cff924e27ef 100644 --- a/lib/gitlab/ci/trace/http_io.rb +++ b/lib/gitlab/ci/trace/http_io.rb @@ -75,18 +75,28 @@ module Gitlab end end - def read(length = nil) + def read(length = nil, outbuf = "") out = "" - until eof? || (length && out.length >= length) + length ||= size - tell + + until length <= 0 || eof? data = get_chunk break if data.empty? - out << data - @tell += data.bytesize + chunk_bytes = [BUFFER_SIZE - chunk_offset, length].min + chunk_data = data.byteslice(0, chunk_bytes) + + out << chunk_data + @tell += chunk_data.bytesize + length -= chunk_data.bytesize end - out = out[0, length] if length && out.length > length + # If outbuf is passed, we put the output into the buffer. This supports IO.copy_stream functionality + if outbuf + outbuf.slice!(0, outbuf.bytesize) + outbuf << out + end out end @@ -158,7 +168,7 @@ module Gitlab # Provider: GCS # - When the file size is larger than requested Content-range, the Content-range is included in responces with Net::HTTPPartialContent 206 # - When the file size is smaller than requested Content-range, the Content-range is included in responces with Net::HTTPOK 200 - @chunk_range ||= (chunk_start...(chunk_start + @chunk.length)) + @chunk_range ||= (chunk_start...(chunk_start + @chunk.bytesize)) end @chunk[chunk_offset..BUFFER_SIZE] |