GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Commit f390be8a authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Merge branch 'enforce-Ansi2html-output-encoding' into 'master'

Just enforce the output encoding for Ansi2html

See merge request !10758
parents 554d2974 fb60c618
---
title: Fix trace cannot be written due to encoding
merge_request: 10758
author:
......@@ -172,7 +172,7 @@ def convert(stream, new_state)
close_open_tags()
OpenStruct.new(
html: @out,
html: @out.force_encoding(Encoding.default_external),
state: state,
append: append,
truncated: truncated,
......
......@@ -14,14 +14,7 @@ class Stream
def initialize
@stream = yield
if @stream
@stream.binmode
# Ci::Ansi2html::Converter would read from @stream directly,
# using @stream.each_line to be specific. It's safe to set
# the encoding here because IO#seek(bytes) and IO#read(bytes)
# are not characters based, so encoding doesn't matter to them.
@stream.set_encoding(Encoding.default_external)
end
@stream&.binmode
end
def valid?
......@@ -68,8 +61,8 @@ def html_with_state(state = nil)
def html(last_lines: nil)
text = raw(last_lines: last_lines)
stream = StringIO.new(text)
::Ci::Ansi2html.convert(stream).html
buffer = StringIO.new(text)
::Ci::Ansi2html.convert(buffer).html
end
def extract_coverage(regex)
......
......@@ -71,12 +71,20 @@
end
describe '#append' do
let(:tempfile) { Tempfile.new }
let(:stream) do
described_class.new do
StringIO.new("12345678")
tempfile.write("12345678")
tempfile.rewind
tempfile
end
end
after do
tempfile.unlink
end
it "truncates and append content" do
stream.append("89", 4)
stream.seek(0)
......@@ -84,6 +92,17 @@
expect(stream.size).to eq(6)
expect(stream.raw).to eq("123489")
end
it 'appends in binary mode' do
'😺'.force_encoding('ASCII-8BIT').each_char.with_index do |byte, offset|
stream.append(byte, offset)
end
stream.seek(0)
expect(stream.size).to eq(4)
expect(stream.raw).to eq('😺')
end
end
describe '#set' 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