-
Notifications
You must be signed in to change notification settings - Fork 110
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
Remove invalid ESC control sequence from XML output #230
Conversation
Would be great if this can be reviewed and possibly merged - i'm seeing some flaky-ness using this :( |
Here's our patch on 14.0.1 while we're awaiting upstream review and fix/release.
|
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.
Sorry for the delay reviewing this. I was traveling for work and then was ill.
I left a comment for you to review.
I would like to avoid simple string replacements and try to utilize strip-ansi or something similar. I already have logic that attempts to remove these characters from failure tags so perhaps that logic needs to be adjusted.
index.js
Outdated
@@ -34,8 +34,12 @@ const processor = (report, reporterOptions = {}, jestRootDir = null) => { | |||
// Ensure output path exists | |||
mkdirp.sync(path.dirname(outputPath)); | |||
|
|||
// Clean ESC character, which is invalid XML and some libraries include in error messages | |||
const xmlString = xml(jsonResults, { indent: ' ', declaration: true }); | |||
const cleanedXmlString = xmlString.replace(/\u001b/g, ''); |
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.
Instead of doing a simple string replace can you see if you can utilize something more generic like strip-ansi?
We use that package when generating the failure tag. So perhaps it needs to be included here or tweaked.
See https://github.com/jest-community/jest-junit/blob/master/utils/buildJsonResults.js#L77
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.
Thank you for the pointer. I've collocated my regexp replace with the existing function.
strip-ansi
is already operating on the offending string, but it appears that strip-ansi
strips only ANSI escape codes, which are ESC plus some characters. But it doesn't also strip plain ASCII control characters like ESC, which are illegal in the XML spec.
I failed to find a suitable package on the npm registry. I did find a snippet https://gist.github.com/john-doherty/b9195065884cdbfd2017a4756e6409cc from @john-doherty that appears to be more robust than my naive approach. I initially wanted to keep the scope of the change small, but if you prefer, I can inline a copy with attribution or work with the author to publish it as a separate package with appropriate license. @palmerj3, please just let me know as I'm happy to follow your preference.
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.
Cool thanks for clarifying. Your implementation looks fine to me so let's roll with that.
Running the CI job now. If all looks good I'll merge and cut a release in the morning.
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.
It looks like the checks passed.
Sorry for the ping. It's not urgent for us since we've already patched locally, but it looks like there's one other PR that intersects and a couple of downstream projects that could use this fix. Thanks for your attention here and hope you're doing better!
Thanks for the hard work! This is now published in jest-junit 15.0.0 |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jest-junit](https://togithub.com/jest-community/jest-junit) | [`14.0.1` -> `15.0.0`](https://renovatebot.com/diffs/npm/jest-junit/14.0.1/15.0.0) | [![age](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/compatibility-slim/14.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/confidence-slim/14.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>jest-community/jest-junit</summary> ### [`v15.0.0`](https://togithub.com/jest-community/jest-junit/releases/tag/v15.0.0) [Compare Source](https://togithub.com/jest-community/jest-junit/compare/v14.0.1...v15.0.0) Remove invalid ESC control sequence from XML output [https://github.com/jest-community/jest-junit/pull/230](https://togithub.com/jest-community/jest-junit/pull/230) - by [@​stevenxu-db](https://togithub.com/stevenxu-db) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/apollographql/apollo-server). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNy4zIiwidXBkYXRlZEluVmVyIjoiMzQuMjcuMyJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jest-junit](https://togithub.com/jest-community/jest-junit) | [`^14.0.0` -> `^15.0.0`](https://renovatebot.com/diffs/npm/jest-junit/14.0.1/15.0.0) | [![age](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/compatibility-slim/14.0.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jest-junit/15.0.0/confidence-slim/14.0.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>jest-community/jest-junit</summary> ### [`v15.0.0`](https://togithub.com/jest-community/jest-junit/releases/tag/v15.0.0) [Compare Source](https://togithub.com/jest-community/jest-junit/compare/v14.0.1...v15.0.0) Remove invalid ESC control sequence from XML output [https://github.com/jest-community/jest-junit/pull/230](https://togithub.com/jest-community/jest-junit/pull/230) - by [@​stevenxu-db](https://togithub.com/stevenxu-db) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/ws-4020/mobile-app-crib-notes). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNy4zIiwidXBkYXRlZEluVmVyIjoiMzQuMjcuMyJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This change forcibly deletes any occurrences of the ESC control sequence in the output XML file.
RTL emits the ESC control sequence
\u001b
or\x1B
sometimes, and thexml
package doesn't escape or exclude it. This is not valid XML and causes some parsers, including the one used in this package's unit tests, to fail. #197 was a previous report of this.Without this fix, the newly added test fails with an XML parse error.
We could also fix in
xml
but that project appears less actively maintained, and given nobody has reported this it may not be a widespread problem worth messing with.This also fixes leaking state between some tests.