summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-17 11:37:19 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-04-17 11:37:19 +0000
commit970f962451a18a5ba0441b9d869a4cb5bc9b97a3 (patch)
tree789408112dac8edc0c089b4a975781ff2166068c
parenteeaeb2752a589c9046659d58d4a3f6be8030b699 (diff)
parent9350b9064cb9c5048f9eab8041e953a5dab5b154 (diff)
downloadgitlab-ce-970f962451a18a5ba0441b9d869a4cb5bc9b97a3.tar.gz
Merge branch 'fix-trace-encoding' into 'master'
Explicitly give Encoding.default_external for trace Closes #30796 See merge request !10728
-rw-r--r--changelogs/unreleased/fix-trace-encoding.yml4
-rw-r--r--lib/gitlab/ci/trace/stream.rb11
-rw-r--r--spec/lib/gitlab/ci/trace/stream_spec.rb20
3 files changed, 31 insertions, 4 deletions
diff --git a/changelogs/unreleased/fix-trace-encoding.yml b/changelogs/unreleased/fix-trace-encoding.yml
new file mode 100644
index 00000000000..152610c43f5
--- /dev/null
+++ b/changelogs/unreleased/fix-trace-encoding.yml
@@ -0,0 +1,4 @@
+---
+title: Fix another case where trace does not have proper encoding set
+merge_request: 10728
+author:
diff --git a/lib/gitlab/ci/trace/stream.rb b/lib/gitlab/ci/trace/stream.rb
index 3b335cdfd01..b929bdd55bc 100644
--- a/lib/gitlab/ci/trace/stream.rb
+++ b/lib/gitlab/ci/trace/stream.rb
@@ -14,6 +14,14 @@ module Gitlab
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
end
def valid?
@@ -51,7 +59,7 @@ module Gitlab
read_last_lines(last_lines)
else
stream.read
- end
+ end.force_encoding(Encoding.default_external)
end
def html_with_state(state = nil)
@@ -113,7 +121,6 @@ module Gitlab
end
chunks.join.lines.last(last_lines).join
- .force_encoding(Encoding.default_external)
end
end
end
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index 9e3bd6d662f..03f040f4465 100644
--- a/spec/lib/gitlab/ci/trace/stream_spec.rb
+++ b/spec/lib/gitlab/ci/trace/stream_spec.rb
@@ -43,13 +43,29 @@ describe Gitlab::Ci::Trace::Stream do
it 'forwards to the next linefeed, case 1' do
stream.limit(7)
- expect(stream.raw).to eq('')
+ result = stream.raw
+
+ expect(result).to eq('')
+ expect(result.encoding).to eq(Encoding.default_external)
end
it 'forwards to the next linefeed, case 2' do
stream.limit(29)
- expect(stream.raw).to eq("\e[01;32m許功蓋\e[0m\n")
+ result = stream.raw
+
+ expect(result).to eq("\e[01;32m許功蓋\e[0m\n")
+ expect(result.encoding).to eq(Encoding.default_external)
+ end
+
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/30796
+ it 'reads in binary, output as Encoding.default_external' do
+ stream.limit(52)
+
+ result = stream.html
+
+ expect(result).to eq("ヾ(´༎ຶД༎ຶ`)ノ<br><span class=\"term-fg-green\">許功蓋</span><br>")
+ expect(result.encoding).to eq(Encoding.default_external)
end
end
end