Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle \e[0;m sequence #3

Open
b-a-t opened this issue Apr 19, 2024 · 0 comments
Open

Handle \e[0;m sequence #3

b-a-t opened this issue Apr 19, 2024 · 0 comments

Comments

@b-a-t
Copy link

b-a-t commented Apr 19, 2024

Are you in the right place?

  • For issues or feature requests file a GitHub issue in this repository
  • For general questions or discussion post on StackOverflow

Describe the problem

gitlab-runner for whatever reason dumps its logs to the syslog with ANSI sequences, which is.. annoying. So, I was trying to sanitize those log lines in fluentd with the help of the sanitize method from the strings-ansi package but failed. It looks like the generated \e[0;m sequence is not handled properly by the regexp in the code.

Steps to reproduce the problem

  def list2string(values)
    values.map(&:chr).join('')
  end

  def test
    message = list2string([ 82, 117, 110, 116, 105, 109, 101, 32, 112, 108, 97, 116, 102, 111, 114, 109, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 27, 91, 48, 59, 109, 32, 32, 97, 114, 99, 104, 27, 91, 48, 59, 109, 61, 97, 109, 100, 54, 52, 32, 111, 115, 27, 91, 48, 59, 109, 61,
 108, 105, 110, 117, 120, 32, 112, 105, 100, 27, 91, 48, 59, 109, 61, 51, 55, 56, 48, 52, 32, 114, 101, 118, 105, 115, 105, 111, 110, 27, 91, 48, 59, 109, 61, 56, 49, 97, 98, 48, 55, 102, 5
4, 32, 118, 101, 114, 115, 105, 111, 110, 27, 91, 48, 59, 109, 61, 49, 54, 46, 49, 48, 46, 48 ])

    print(message)

    new_message = Strings::ANSI.sanitize(message)

    print(new_message)

    assert_equal('Runtime platform                                    arch=amd64 os=linux pid=37804 revision=81ab07f6 version=16.10.0', new_message)
  end

Actual behaviour

The sanitized string is still looks:

Runtime platform                                  \e[0;m  arch\e[0;m=amd64 os\e[0;m=linux pid\e[0;m=37804 revision\e[0;m=81ab07f6 version\e[0;m=16.10.0

Expected behaviour

The output should be:

Runtime platform                                    arch=amd64 os=linux pid=37804 revision=81ab07f6 version=16.10.0

Describe your environment

  • OS version: Red Hat Enterprise Linux release 8.9 (Ootpa)
  • Ruby version: 3.2.3
  • Strings::ANSI version: 0.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant