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

Cobertura XML is malformed: unescaped quotes in filename string #302

Open
DLehenbauer opened this issue Apr 30, 2021 · 4 comments
Open

Cobertura XML is malformed: unescaped quotes in filename string #302

DLehenbauer opened this issue Apr 30, 2021 · 4 comments
Labels

Comments

@DLehenbauer
Copy link

DLehenbauer commented Apr 30, 2021

  • Version: v12.18.3
  • Platform: Linux d35e72cef690 5.4.72-microsoft-standard-WSL2 Detailed coverage #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 GNU/Linux

I'm guessing this is a trivial matter of needing to escapify filenames, but am happy to help produce a minimal repro if it would be helpful.

The malformed XML is an unquoted string that occurs when our coverage run includes a webpack'ed bundle that references react as an external module:

<class name="external &quot;react&quot;" filename="../../@fluid-experimental/property-inspector-table/external "react"" line-rate="1" branch-rate="1">

(PS - Great project!)

@bcoe
Copy link
Owner

bcoe commented May 5, 2021

@DLehenbauer thank you for the bug report. We may need to fix this upstream in the reporting module:

https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib/cobertura

We fixed a similar bug in the past, does anything jump out at you, as to where I've missed escaping?

@DLehenbauer
Copy link
Author

DLehenbauer commented May 6, 2021

Thank you for taking a look. I thought it might be an easy one to spot from code inspection, sorry.

Here's a reduced repro:

git clone https://github.com/DLehenbauer/c8-repro.git
cd c8-repro
npm i
npm run build
npm run test:coverage
head nyc/report/cobertura-coverage.xml

Line 10 of the XML is malformed as shown above.

The problem seems to be related to using webpack externals to omit 'react' from the bundle.

If you remove the line indicated below from the bottom of webpack.prod.js and re-run coverage the resulting XML is valid.

    externals: [{
      'react': 'react',                 <<-- Delete me
      ...
    }],

(Let me know if you have any trouble w/the repo. I can reduce more if it helps.)

@DLehenbauer
Copy link
Author

Hi @bcoe - Does this just need escape(..) around the filename when emitting the <class> tag on line 85?
https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib/cobertura

curtisman added a commit to microsoft/FluidFramework that referenced this issue Aug 27, 2021
Some webpacked file using externals introduce file name with quotes in them and Istanbul's cobertura reporter doesn't escape them causing parse error when we publish. A quick fix to patch the file with sed to escape the quotes. (See bcoe/c8#302)
@bcoe
Copy link
Owner

bcoe commented Sep 7, 2021

Does this just need escape(..) around the filename when emitting the

@DLehenbauer I believe you're right that it's probably just a missing escape in that upstream repository, bother you to submit a patch and I should be able to approve?

curtisman added a commit to microsoft/FluidFramework that referenced this issue Jul 8, 2022
Need to update the pattern to patch the code coverage result to work around bcoe/c8#302.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants