This is an archive of the discontinued LLVM Phabricator instance.

[sancov] coverage-report-server.py: ServerHandler(): open file as UTF8
ClosedPublic

Authored by lebedev.ri on Sep 9 2017, 3:11 AM.

Details

Summary

This is nessesary in Python3. Everywhere else we assume that
encoding is UTF8. If we don't specify it here, the defaults
from the environment will be used, which may result in ASCII
decoder being used. And if the file is non-ASCII, then it
will crash:

  File "/usr/local/bin/coverage-report-server.py", line 168, in do_GET
    for line_no, line in enumerate(f, start=1)])
  File "/usr/local/bin/coverage-report-server.py", line 165, in <listcomp>
    ["<span class='{cls}'>{line}&nbsp;</span>".format(
  File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 106: ordinal not in range(128)

Fixes https://bugs.llvm.org/show_bug.cgi?id=33548

Now, how would i add a testcase here?

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.Sep 9 2017, 3:11 AM
kcc added a subscriber: kcc.Sep 12 2017, 11:50 AM

can we just stick to python2?
I am not sure for how long this code will survive (I hope to migrate to clang's SourceBasedCodeCoverage) and don't want to spend time improving it.

kcc edited reviewers, added: kcc; removed: aizatsky.Sep 12 2017, 11:50 AM
lebedev.ri added a comment.EditedSep 12 2017, 11:52 AM
In D37661#868351, @kcc wrote:

can we just stick to python2?
I am not sure for how long this code will survive (I hope to migrate to clang's SourceBasedCodeCoverage) and don't want to spend time improving it.

Right now that script hardcodes python3:

#!/usr/bin/env python3

IMHO python2 is dead, and really, really should not be used for anything new.

kcc accepted this revision.Sep 12 2017, 11:56 AM

LGTM

I don't think we have any tests for this script :(

This revision is now accepted and ready to land.Sep 12 2017, 11:56 AM
This revision was automatically updated to reflect the committed changes.