提交 9350b906 编写于 作者: L Lin Jen-Shin

Set the encoding in c'tor and explain why it's fine

上级 bb10b231
...@@ -14,7 +14,14 @@ module Gitlab ...@@ -14,7 +14,14 @@ module Gitlab
def initialize def initialize
@stream = yield @stream = yield
@stream.binmode if @stream 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
end end
def valid? def valid?
...@@ -56,14 +63,12 @@ module Gitlab ...@@ -56,14 +63,12 @@ module Gitlab
end end
def html_with_state(state = nil) def html_with_state(state = nil)
set_encoding_for_ansi2html
::Ci::Ansi2html.convert(stream, state) ::Ci::Ansi2html.convert(stream, state)
end end
def html(last_lines: nil) def html(last_lines: nil)
text = raw(last_lines: last_lines) text = raw(last_lines: last_lines)
stream = StringIO.new(text) stream = StringIO.new(text)
set_encoding_for_ansi2html(stream)
::Ci::Ansi2html.convert(stream).html ::Ci::Ansi2html.convert(stream).html
end end
...@@ -117,11 +122,6 @@ module Gitlab ...@@ -117,11 +122,6 @@ module Gitlab
chunks.join.lines.last(last_lines).join chunks.join.lines.last(last_lines).join
end end
def set_encoding_for_ansi2html(stream = @stream)
# Ci::Ansi2html::Converter would read from @stream directly
stream.set_encoding(Encoding.default_external)
end
end end
end end
end end
......
...@@ -64,7 +64,7 @@ describe Gitlab::Ci::Trace::Stream do ...@@ -64,7 +64,7 @@ describe Gitlab::Ci::Trace::Stream do
result = stream.html result = stream.html
expect(result.lines.first).to eq("ヾ(´༎ຶД༎ຶ`)ノ<br><span class=\"term-fg-green\">許功蓋</span><br>") expect(result).to eq("ヾ(´༎ຶД༎ຶ`)ノ<br><span class=\"term-fg-green\">許功蓋</span><br>")
expect(result.encoding).to eq(Encoding.default_external) expect(result.encoding).to eq(Encoding.default_external)
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册