Skip to content

Fixes incorrect wrapping in styled log lines

What does this MR do and why?

Fixes #465945 (closed)

This change fixes the wrapping of text in long lines that are incorrectly shown side-by-side instead of inline.

Changelog: fixed

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
image image

How to set up and validate locally

Simple verification

This problem occurs when a a log line is both long and contains several ANSI styles.

Using a a bash shell (I tested in macOS, but Linux should work), it's possible to render such a long line with the following .gitlab-ci.yml

stages:
  - build

job:
  stage: build
  before_script:
    - TXT_RED="\033[31m" && TXT_CLEAR="\033[0m"
  script:
    - echo -e "${TXT_RED}This is a long line of text, and this text is red, and this text is red, and this text is red,${TXT_CLEAR} but this part isn't${TXT_RED} however this part is red once more in this long line."
    - echo "This text is not colored"

After this you can run a job using a runner with a shell executor.

Extended verification

It's possible to replace the entire contents of a log shown locally by downloading a raw file locally and using the following patch:

diff --git a/lib/gitlab/ci/ansi2json.rb b/lib/gitlab/ci/ansi2json.rb
index 79114d35916c..a0256ca5d2c9 100644
--- a/lib/gitlab/ci/ansi2json.rb
+++ b/lib/gitlab/ci/ansi2json.rb
@@ -5,7 +5,10 @@ module Gitlab
   module Ci
     module Ansi2json
       def self.convert(ansi, state = nil)
-        Converter.new.convert(ansi, state)
+        # Converter.new.convert(ansi, state)
+        File.open("/Users/miguelrincon/Downloads/jobs-7009875344.txt", "r") do |stream|
+          Converter.new.convert(stream, state)
+        end
       end
     end
   end

In particular, I was able to reproduce this with https://gitlab.com/gitlab-org/gitlab/-/jobs/7009875344#L3134.

current locally replaced
image image
Full log view

entire-log

Edited by Miguel Rincon

Merge request reports

Loading