joshy / striprtf

Stripping rtf to plain old text
http://striprtf.dev
BSD 3-Clause "New" or "Revised" License
94 stars 27 forks source link

AttributeError when out variable is instance of bytes #22

Closed ap-Codkelden closed 3 years ago

ap-Codkelden commented 3 years ago

This part of code (striprtf.py, line 113) may cause to an error

AttributeError: 'bytes' object has no attribute 'append'

if out variable is instance of bytes:

elif char in "{}\\":
    if not ignorable:
        out.append(char)

RTF for checkout: http://od.reyestr.court.gov.ua/files/39/29929d5dd1e13dc3e8f448c57051a854.rtf

I think, it can be fixed like this:

if not ignorable:
    if isinstance(out, bytes):
        out = out + char.encode()
    else:
        out.append(char)