Menu

Bug - unicode decode error

cmm
2016-03-29
2016-03-29
  • cmm

    cmm - 2016-03-29

    Hello,
    First of all, thank you very much for CppHeaderParser - a very useful tool. I have been using it over the past few days and came across an error in reading source files that may have utf-8 encoding:

    header = CppHeaderParser.CppHeader(self.path);
      File "/usr/local/lib/python3.5/site-packages/CppHeaderParser/CppHeaderParser.py", line 2094, in __init__
        headerFileStr = "".join(fd.readlines())
      File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/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 69: ordinal not in range(128)
    

    I changed the following at (roughly) line 2088 in CppHeaderParser.py:

            if (len(self.headerFileName)):
                    #fd = open(self.headerFileName)
                    fd = open(self.headerFileName, encoding='utf-8')
                    headerFileStr = "".join(fd.readlines())
                    fd.close()
    

    This seems to solve the issue, but I am not sure what methods need to be tested to ensure this doesn't cause other problems.

     
  • Jashua Cloutier

    Jashua Cloutier - 2016-03-29

    Can you attach a file that demonstrates the issue please?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.