-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: ensure that the xunit reporter emits well-formed XML #5001
Conversation
|
XML does not allow certain characters to appear in documents. This change ensures that those restricted characters are replaced by legal characters. This bug means that when a test ends up containing, for example, ANSI color codes (i.e. `[36m<div[39m`) then the generated XML file is invalid and some consumers (such as CircleCI) are unable to parse the contents. Link: https://www.w3.org/TR/2006/REC-xml11-20060816/#charsets
dfe272c
to
c953873
Compare
@@ -35,6 +36,7 @@ exports.inherits = util.inherits; | |||
* @return {string} | |||
*/ | |||
exports.escape = function (html) { | |||
html = html.toString().replaceAll(RESTRICTED_CHAR, "�"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 this looks like a duplicate of #4527. @malloryavvir do you have thoughts on https://github.com/mochajs/mocha/pull/4527/files#r1511131215 ?
👋 ping @malloryavvir, is this still something you have time for? |
@JoshuaKGoldberg I've been pretty busy lately. I'm afraid I don't have the capacity to look at this. Thanks for reaching out though. |
No worries, thanks for letting us know! I'll close this out so that anybody who has time + energy can approach it. If a PR is sent based on code form this one, it should include a co-authored-by attribution. Cheers! |
Edit: I have updated this PR to fix the bug in addition to creating a failing test.
Description of the Change
From the PR:
Alternate Designs
This is a lossy conversion. An alternative to displaying the replacement character would be to display some message explaining what character has been replaced. This is a lot less verbose and will be easier to read when your tests are outputting ANSI control codes, and if the original text is needed you can rerun the tests locally.
Why should this be in core?
This is a bug. Mocha is generating malformed XML documents that cannot be parsed.
Benefits
XML documents generated by the XUnit reporter are now well-formed and thus can be parsed.
Possible Drawbacks
It's a lossy conversion. Probably 99% of the time it's going to be an ANSI control code being removed.
Applicable issues
This is a bug fix.