Skip to content

ANSI escape codes in messages break xunit file #2955

@jkrems

Description

@jkrems

When the error message or stack contains any non-safe characters, it breaks the xunit file and the resulting report is no longer valid XML.

Repro:

# Explicit:
npm init --yes
npm i -D mocha
echo "it('throws', () => { throw new Error('\x1B[32mfoo\x1B[0m'); })">test.js
./node_modules/.bin/mocha -R xunit -O output=report.xml test.js

# One-liner:
npm init --yes >/dev/null && npm i -D mocha >/dev/null && echo "it('throws', () => { throw new Error('\x1B[32mfoo\x1B[0m'); })">test.js && ./node_modules/.bin/mocha -R xunit -O output=report.xml test.js

Running report.xml through an online validator will trigger messages like the following:

An invalid XML character (Unicode: 0x1b) was found in the element content of the document.

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