summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-04-17 17:52:15 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-04-17 17:52:15 +0800
commit9350b9064cb9c5048f9eab8041e953a5dab5b154 (patch)
tree789408112dac8edc0c089b4a975781ff2166068c
parentbb10b23194a3f3332096168fa0e0fd297f846307 (diff)
downloadgitlab-ce-fix-trace-encoding.tar.gz
Set the encoding in c'tor and explain why it's finefix-trace-encoding
-rw-r--r--lib/gitlab/ci/trace/stream.rb16
-rw-r--r--spec/lib/gitlab/ci/trace/stream_spec.rb2
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb
index 757a8e2dc6a..b929bdd55bc 100644
--- a/lib/gitlab/ci/trace/stream.rb
+++ b/lib/gitlab/ci/trace/stream.rb
@@ -14,7 +14,14 @@ module Gitlab
def initialize
@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
def valid?
@@ -56,14 +63,12 @@ module Gitlab
end
def html_with_state(state = nil)
- set_encoding_for_ansi2html
::Ci::Ansi2html.convert(stream, state)
end
def html(last_lines: nil)
text = raw(last_lines: last_lines)
stream = StringIO.new(text)
- set_encoding_for_ansi2html(stream)
::Ci::Ansi2html.convert(stream).html
end
@@ -117,11 +122,6 @@ module Gitlab
chunks.join.lines.last(last_lines).join
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
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index 28d5c2183ce..03f040f4465 100644
--- a/spec/lib/gitlab/ci/trace/stream_spec.rb
+++ b/spec/lib/gitlab/ci/trace/stream_spec.rb
@@ -64,7 +64,7 @@ describe Gitlab::Ci::Trace::Stream do
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)
end
end