Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
9350b906
Commit
9350b906
authored
Apr 17, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the encoding in c'tor and explain why it's fine
parent
bb10b231
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
lib/gitlab/ci/trace/stream.rb
lib/gitlab/ci/trace/stream.rb
+8
-8
spec/lib/gitlab/ci/trace/stream_spec.rb
spec/lib/gitlab/ci/trace/stream_spec.rb
+1
-1
No files found.
lib/gitlab/ci/trace/stream.rb
View file @
9350b906
...
@@ -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
...
...
spec/lib/gitlab/ci/trace/stream_spec.rb
View file @
9350b906
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment