victorolinasc / junit-formatter

A JUnit XML report exporter for Elixir's ExUnit
https://hexdocs.pm/junit_formatter/
Apache License 2.0
110 stars 37 forks source link

Converts String to utf8 charlist, instead of unicode #34

Closed mrmstn closed 5 years ago

mrmstn commented 5 years ago

I had a issue with special chars like öäü. As soon as they appeard in a test content, for example as error message, those characters corrupted the junit xml, since were invalid utf8 characters (�)

Here's a example of the xmllint output:

 parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xFC 0x73 0x69 0x6E
tionships" => %{}, "type" => "invoice"}">  1) test DE-B

After a little bit of debugging, I've found the issue. String.to_charlist will convert the String to a list of Unicode representivs but the xmerl_lib expects utf8 characters

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-2.2%) to 95.652% when pulling 10f4a117fa505da8344606a0505aa469ec3914b6 on cyon:mr/unicode-utf8 into 6716554ee36cb9bed0c241d58aa8e59caa75ec61 on victorolinasc:master.

victorolinasc commented 5 years ago

Hey @mrmstn thanks a lot for your report and PR!

What is strange is that I think this happened before and I thought we had a test for that... Look at these commits:

Sorry that this happened once again. Can you add a test on your PR just to be 200% certain this will not happen again (it probably will cause it is very subtle and any refactoring might bring this back)?

Once again, thanks for your report!

mrmstn commented 5 years ago

@victorolinasc Thank you very much for your response, I should have thought about the tests.

I tried to add some failing tests for the codebase without my fix, but strangly - file writing process died instantly with the following error message ( as soon as there were any unicode chars in the failure message):

     ** (exit) exited in: GenServer.stop(#PID<0.205.0>, :normal, 30000)
         ** (EXIT) exited in: :sys.terminate(#PID<0.205.0>, :normal, :infinity)
             ** (EXIT) an exception was raised:
                 ** (File.Error) could not write to file "<path to project>/junit-formatter/_build/test/lib/junit_formatter/report_file_test.xml": bad argument
                     (elixir) lib/file.ex:953: File.write!/3
                     (junit_formatter) lib/formatter.ex:77: JUnitFormatter.handle_cast/2
                     (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
                     (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
                     (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

So I guess as long as we can convert the charlist back to the same string, there shouldn't be a issue with unicodes in the body

victorolinasc commented 5 years ago

The error seems like the file has a wrong name <path to project>/junit-formatter/_build/test/lib/junit_formatter/report_file_test.xml...

I'll take a look after I merge this.

Thanks once again!