summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/ansi2json/line.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/ansi2json/line.rb')
-rw-r--r--lib/gitlab/ci/ansi2json/line.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/gitlab/ci/ansi2json/line.rb b/lib/gitlab/ci/ansi2json/line.rb
index 8f2d47e7ccc..e48080993ab 100644
--- a/lib/gitlab/ci/ansi2json/line.rb
+++ b/lib/gitlab/ci/ansi2json/line.rb
@@ -9,6 +9,8 @@ module Gitlab
# Line::Segment is a portion of a line that has its own style
# and text. Multiple segments make the line content.
class Segment
+ include EncodingHelper
+
attr_accessor :text, :style
def initialize(style:)
@@ -21,11 +23,12 @@ module Gitlab
end
def to_h
- # Without force encoding to UTF-8 we could get an error
- # when serializing the Hash to JSON.
+ # Without forcing the encoding to UTF-8 and then replacing
+ # invalid UTF-8 sequences we can get an error when serializing
+ # the Hash to JSON.
# Encoding::UndefinedConversionError:
# "\xE2" from ASCII-8BIT to UTF-8
- { text: text.force_encoding('UTF-8') }.tap do |result|
+ { text: encode_utf8_no_detect(text) }.tap do |result|
result[:style] = style.to_s if style.set?
end
end