summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/ansi2json
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/ci/ansi2json
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/ci/ansi2json')
-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