Skip to content

Commit

Permalink
Fix issue deanmalmgren#342
Browse files Browse the repository at this point in the history
Clarification, _getStringStream *should* return `unicode` in Python 2, `str` in Python 3, IF the stream requested exists. If it does not exist, it returns `None`, which cannot be added to bytes. This commit adds a check for None, returning an empty bytes string if matched.
  • Loading branch information
TheElementalOfDestruction authored Jun 16, 2022
1 parent 102a584 commit 7096fd9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion textract/parsers/msg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
def ensure_bytes(string):
"""Normalize string to bytes.
`ExtractMsg.Message._getStringStream` can return unicode or bytes depending
`extract_msg.Message._getStringStream` can return unicode or bytes depending
on what is originally stored in message file.
This helper functon makes sure, that bytes type is returned.
"""
if isinstance(string, six.string_types):
return string.encode('utf-8')
if string is None:
return b''
return string


Expand Down

0 comments on commit 7096fd9

Please sign in to comment.