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
ad96cc0e
Commit
ad96cc0e
authored
Jun 14, 2019
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing specs
parent
cb0616fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
29 deletions
+40
-29
lib/gitlab/ci/ansi2html.rb
lib/gitlab/ci/ansi2html.rb
+5
-2
spec/lib/gitlab/ci/ansi2html_spec.rb
spec/lib/gitlab/ci/ansi2html_spec.rb
+35
-27
No files found.
lib/gitlab/ci/ansi2html.rb
View file @
ad96cc0e
...
...
@@ -187,6 +187,10 @@ module Gitlab
)
end
def
section_to_class_name
(
section
)
section
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
end
def
handle_new_line
css_classes
=
[]
...
...
@@ -208,8 +212,7 @@ module Gitlab
section
=
scanner
[
3
]
line
=
scanner
.
matched
[
0
...-
5
]
# strips \r\033[0K
# generate section class
normalized_section
=
section
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
normalized_section
=
section_to_class_name
(
section
)
if
action
==
"start"
handle_section_start
(
normalized_section
,
timestamp
,
line
)
...
...
spec/lib/gitlab/ci/ansi2html_spec.rb
View file @
ad96cc0e
...
...
@@ -4,11 +4,11 @@ describe Gitlab::Ci::Ansi2html do
subject
{
described_class
}
it
"prints non-ansi as-is"
do
expect
(
convert_html
(
"Hello"
)).
to
eq
(
'
Hello
'
)
expect
(
convert_html
(
"Hello"
)).
to
eq
(
'
<span class="">Hello</span>
'
)
end
it
"strips non-color-changing control sequences"
do
expect
(
convert_html
(
"Hello
\e
[2Kworld"
)).
to
eq
(
'
Hello world
'
)
expect
(
convert_html
(
"Hello
\e
[2Kworld"
)).
to
eq
(
'
<span class="">Hello world</span>
'
)
end
it
"prints simply red"
do
...
...
@@ -32,7 +32,7 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets colors after red on blue"
do
expect
(
convert_html
(
"
\e
[31;44mHello
\e
[0m world"
)).
to
eq
(
'<span class="term-fg-red term-bg-blue">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[31;44mHello
\e
[0m world"
)).
to
eq
(
'<span class="term-fg-red term-bg-blue">Hello</span>
<span class=""> world</span>
'
)
end
it
"performs color change from red/blue to yellow/blue"
do
...
...
@@ -44,11 +44,11 @@ describe Gitlab::Ci::Ansi2html do
end
it
"performs color change from red/blue to reset to yellow/green"
do
expect
(
convert_html
(
"
\e
[31;44mHello
\e
[0m
\e
[33;42mworld"
)).
to
eq
(
'<span class="term-fg-red term-bg-blue">Hello</span>
<span class="term-fg-yellow term-bg-green">world</span>'
)
expect
(
convert_html
(
"
\e
[31;44mHello
\e
[0m
\e
[33;42mworld"
)).
to
eq
(
'<span class="term-fg-red term-bg-blue">Hello</span>
<span class=""> </span>
<span class="term-fg-yellow term-bg-green">world</span>'
)
end
it
"ignores unsupported codes"
do
expect
(
convert_html
(
"
\e
[51mHello
\e
[0m"
)).
to
eq
(
'
Hello
'
)
expect
(
convert_html
(
"
\e
[51mHello
\e
[0m"
)).
to
eq
(
'
<span class="">Hello</span>
'
)
end
it
"prints light red"
do
...
...
@@ -72,8 +72,8 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets bold text"
do
expect
(
convert_html
(
"
\e
[1mHello
\e
[21m world"
)).
to
eq
(
'<span class="term-bold">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[1mHello
\e
[22m world"
)).
to
eq
(
'<span class="term-bold">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[1mHello
\e
[21m world"
)).
to
eq
(
'<span class="term-bold">Hello</span>
<span class=""> world</span>
'
)
expect
(
convert_html
(
"
\e
[1mHello
\e
[22m world"
)).
to
eq
(
'<span class="term-bold">Hello</span>
<span class=""> world</span>
'
)
end
it
"prints italic text"
do
...
...
@@ -81,7 +81,7 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets italic text"
do
expect
(
convert_html
(
"
\e
[3mHello
\e
[23m world"
)).
to
eq
(
'<span class="term-italic">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[3mHello
\e
[23m world"
)).
to
eq
(
'<span class="term-italic">Hello</span>
<span class=""> world</span>
'
)
end
it
"prints underlined text"
do
...
...
@@ -89,7 +89,7 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets underlined text"
do
expect
(
convert_html
(
"
\e
[4mHello
\e
[24m world"
)).
to
eq
(
'<span class="term-underline">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[4mHello
\e
[24m world"
)).
to
eq
(
'<span class="term-underline">Hello</span>
<span class=""> world</span>
'
)
end
it
"prints concealed text"
do
...
...
@@ -97,7 +97,7 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets concealed text"
do
expect
(
convert_html
(
"
\e
[8mHello
\e
[28m world"
)).
to
eq
(
'<span class="term-conceal">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[8mHello
\e
[28m world"
)).
to
eq
(
'<span class="term-conceal">Hello</span>
<span class=""> world</span>
'
)
end
it
"prints crossed-out text"
do
...
...
@@ -105,7 +105,7 @@ describe Gitlab::Ci::Ansi2html do
end
it
"resets crossed-out text"
do
expect
(
convert_html
(
"
\e
[9mHello
\e
[29m world"
)).
to
eq
(
'<span class="term-cross">Hello</span>
world
'
)
expect
(
convert_html
(
"
\e
[9mHello
\e
[29m world"
)).
to
eq
(
'<span class="term-cross">Hello</span>
<span class=""> world</span>
'
)
end
it
"can print 256 xterm fg colors"
do
...
...
@@ -137,15 +137,15 @@ describe Gitlab::Ci::Ansi2html do
end
it
"prints <"
do
expect
(
convert_html
(
"<"
)).
to
eq
(
'
<
'
)
expect
(
convert_html
(
"<"
)).
to
eq
(
'
<span class=""><</span>
'
)
end
it
"replaces newlines with line break tags"
do
expect
(
convert_html
(
"
\n
"
)).
to
eq
(
'<
br
>'
)
expect
(
convert_html
(
"
\n
"
)).
to
eq
(
'<
span class=""><br/><span class=""></span></span
>'
)
end
it
"groups carriage returns with newlines"
do
expect
(
convert_html
(
"
\r\n
"
)).
to
eq
(
'<
br
>'
)
expect
(
convert_html
(
"
\r\n
"
)).
to
eq
(
'<
span class=""><br/><span class=""></span></span
>'
)
end
describe
"incremental update"
do
...
...
@@ -166,14 +166,14 @@ describe Gitlab::Ci::Ansi2html do
let
(
:pre_text
)
{
"
\e
[1mHello"
}
let
(
:pre_html
)
{
"<span class=
\"
term-bold
\"
>Hello</span>"
}
let
(
:text
)
{
"
\e
[1mWorld"
}
let
(
:html
)
{
"<span class=
\"
term-bold
\"
>
</span><span class=
\"
term-bold
\"
>
World</span>"
}
let
(
:html
)
{
"<span class=
\"
term-bold
\"
>World</span>"
}
it_behaves_like
'stateable converter'
end
context
"with split sequence"
do
let
(
:pre_text
)
{
"
\e
[1m"
}
let
(
:pre_html
)
{
"
<span class=
\"
term-bold
\"
></span>
"
}
let
(
:pre_html
)
{
""
}
let
(
:text
)
{
"Hello"
}
let
(
:html
)
{
"<span class=
\"
term-bold
\"
>Hello</span>"
}
...
...
@@ -182,7 +182,7 @@ describe Gitlab::Ci::Ansi2html do
context
"with partial sequence"
do
let
(
:pre_text
)
{
"Hello
\e
"
}
let
(
:pre_html
)
{
"
Hello
"
}
let
(
:pre_html
)
{
"
<span class=
\"\"
>Hello</span>
"
}
let
(
:text
)
{
"[1m World"
}
let
(
:html
)
{
"<span class=
\"
term-bold
\"
> World</span>"
}
...
...
@@ -191,9 +191,9 @@ describe Gitlab::Ci::Ansi2html do
context
'with new line'
do
let
(
:pre_text
)
{
"Hello
\r
"
}
let
(
:pre_html
)
{
"
Hello
\r
"
}
let
(
:pre_html
)
{
"
<span class=
\"\"
>Hello
\r
</span>
"
}
let
(
:text
)
{
"
\n
World"
}
let
(
:html
)
{
"<
br>World
"
}
let
(
:html
)
{
"<
span class=
\"\"
><br/><span class=
\"\"
>World</span></span>
"
}
it_behaves_like
'stateable converter'
end
...
...
@@ -207,20 +207,20 @@ describe Gitlab::Ci::Ansi2html do
let
(
:section_start
)
{
"section_start:
#{
section_start_time
.
to_i
}
:
#{
section_name
}
\r\033
[0K"
}
let
(
:section_end
)
{
"section_end:
#{
section_end_time
.
to_i
}
:
#{
section_name
}
\r\033
[0K"
}
let
(
:section_start_html
)
do
'<div class="
hidden" data-action="start"'
\
" data-timestamp=
\"
#{
section_start_time
.
to_i
}
\"
data-section=
\"
#{
section_name
}
\"
>"
\
"
#{
section_start
[
0
...-
5
]
}
</div>"
'<div class="
js-section-start fa fa-caret-down append-right-8 cursor-pointer"'
\
" data-timestamp=
\"
#{
section_start_time
.
to_i
}
\"
data-section=
\"
#{
class_name
(
section_name
)
}
\"
"
\
' role="button"></div>'
end
let
(
:section_end_html
)
do
'<div class="hidden" data-action="end"'
\
" data-timestamp=
\"
#{
section_end_time
.
to_i
}
\"
data-section=
\"
#{
section_name
}
\"
>"
\
"
#{
section_end
[
0
...-
5
]
}
</div>"
"<div class=
\"
section-end
\"
data-section=
\"
#{
class_name
(
section_name
)
}
\"
></div>"
end
shared_examples
'forbidden char in section_name'
do
it
'ignores sections'
do
text
=
"
#{
section_start
}
Some text
#{
section_end
}
"
html
=
text
.
gsub
(
"
\033
[0K"
,
''
).
gsub
(
'<'
,
'<'
)
class_name_start
=
section_start
.
gsub
(
"
\033
[0K"
,
''
).
gsub
(
'<'
,
'<'
)
class_name_end
=
section_end
.
gsub
(
"
\033
[0K"
,
''
).
gsub
(
'<'
,
'<'
)
html
=
%{<span class="">#{class_name_start}Some text#{class_name_end}</span>}
expect
(
convert_html
(
text
)).
to
eq
(
html
)
end
...
...
@@ -231,7 +231,11 @@ describe Gitlab::Ci::Ansi2html do
it
'prints light red'
do
text
=
"
#{
section_start
}
\e
[91mHello
\e
[0m
\n
#{
section_end
}
"
html
=
%{#{section_start_html}<span class="term-fg-l-red">Hello</span><br>#{section_end_html}}
header
=
%{<span class="term-fg-l-red section js-section-header js-s_#{class_name(section_name)}">Hello</span>}
line_break
=
%{<span class="section js-section-header js-s_#{class_name(section_name)}"><br/></span>}
line
=
%{<span class="section s_#{class_name(section_name)} line"></span>}
empty_line
=
%{<span class="section js-s_#{class_name(section_name)}"></span>}
html
=
"
#{
section_start_html
}#{
header
}#{
line_break
}#{
line
}#{
empty_line
}#{
section_end_html
}
"
expect
(
convert_html
(
text
)).
to
eq
(
html
)
end
...
...
@@ -294,4 +298,8 @@ describe Gitlab::Ci::Ansi2html do
stream
=
StringIO
.
new
(
data
)
subject
.
convert
(
stream
).
html
end
def
class_name
(
section
)
subject
::
Converter
.
new
.
section_to_class_name
(
section
)
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