ReportGenerator icon indicating copy to clipboard operation
ReportGenerator copied to clipboard

Code Coverage report response causes garbled characters

Open vinayakmsft opened this issue 1 year ago • 2 comments

There is an API (https://dev.azure.com/shkinosh/6f274600-4e62-414a-b9dc-e51cfa02f0ec/_apis/test/CodeCoverage/browse/30505214/Code%20Coverage%20Report_995/._py.html) which responds without specifying a charset in the Content-Type header of the response.

As a result, the encoding in this iFrame is determined by the browser's guess, and depending on the case, an inappropriate encoding may be used, and the source code displayed in the Code Coverage screen may be garbled if it uses non-ASCII characters.

  • Screenshot or video demonstrating the issue

Garbled characters in code coverage tab:

image

  • What debugging steps have already been tried?

Implemented simple python application to publish Cobertura format code coverage report. With this repro pipeline, I have confirmed that the Japanese characters are garbled even though it is encoded using UTF-8.

image

This issue can be resolved by overwriting response header to include "charset=utf-8" in Content-Type header.

image image

I have confirmed the following two similar reports that have been made so far, but it seems that it was mistakenly understood that the cause of the garbling was "use of multibyte characters that use an encoding other than UTF-8".

In fact, this issue occurs even if the HTML delivered contains strings encoded in UTF-8. the problem occurs because the charset is not specified in the header. Azure DevOps is fully UTF-8 encoding compatible, so I think it's reasonable to expect the strings in UTF-8 be displayed without any problem in this Code Coverage screen.

Is it possible to make a change to specify a charset in the Content-Type header of the response of the above API? Or is there some reason that I am not aware of why the charset is not specified?

vinayakmsft avatar Feb 19 '24 04:02 vinayakmsft

Hi @danielpalme please let me know on this issue

vinayakmsft avatar Feb 21 '24 04:02 vinayakmsft

@vinayakmsft I will come back to you within the next days.

danielpalme avatar Feb 21 '24 07:02 danielpalme

@vinayakmsft ReportGenerator generates the HTML files (UTF8 encoded).

Then these files are probably published via the PublishCodeCoverageResults task within Azure DevOps.

The report can be accessed via the "Code Coverage" tab. Or you can download the corresponding artifact and view the report locally: image If you download the artifact and view the HTML files locally, does it get displayed correctly?

I can't change the behavior of Azure DevOps. If it does not send the "charset=utf-8" in Content-Type header, I can't change that. I can only change the generated HTML files.

danielpalme avatar Feb 22 '24 19:02 danielpalme