Skip to content

ANSI coded output causes Junit formatter to create invalid XML #311

@bioball

Description

@bioball

If outputting text with ANSI controls, the Junit formatter will create invalid XML. For instance:

@test "my-test" {
  printf "\e[1mhello\e[0m"
  return 1
}

Produces this output (with properties redacted)

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="my_test.bats" tests="1" failures="1" errors="0" skipped="0" time="0" timestamp="2020-05-12T15:01:25">
    <testcase classname="my_test.bats" name="my-test" time="0">
        <failure type="failure"><![CDATA[
(in test file test/my_test.bats, line 106)
  `printf "\e[1mhello\e[0m"' failed
�[1mhello�[0m]]></failure>
    </testcase>
  <system-out></system-out>
  <system-err></system-err>
</testsuite>

The CDATA section includes the control character literal (Unicode: 0x1b), which are invalid XML characters. This is causing some XML parsers to fail parsing the resulting file.

I think maybe there's two ways to handle this:

  1. Encode the escape character (as \e or \033 or something)
  2. Strip all control characters from the captured output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions