Skip to content

Commit

Permalink
fix strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Knio authored and ianare committed May 3, 2023
1 parent d0825bb commit fc178d0
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions exifread/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ def make_string(seq: Union[bytes, list]) -> str:
"""
Don't throw an exception when given an out of range character.
"""
string = ''
for char in seq:
# Screen out non-printing characters
try:
if 32 <= char < 256:
string += chr(char)
except TypeError:
pass

# If no printing chars
if not string:
if isinstance(seq, list):
string = ''.join(map(str, seq))
# Some UserComment lists only contain null bytes, nothing valuable to return
if set(string) == {'0'}:
return ''
else:
string = str(seq)
string = ''.join(map(chr,seq))
# for char in seq:
# # Screen out non-printing characters
# try:
# if 32 <= char < 256:
# string += chr(char)
# except TypeError:
# pass

# # If no printing chars
# if not string:
# if isinstance(seq, list):
# string = ''.join(map(str, seq))
# # Some UserComment lists only contain null bytes, nothing valuable to return
# if set(string) == {'0'}:
# return ''
# else:
# string = str(seq)

# Clean undesirable characters on any end
return string.strip(' \x00')
return string


def make_string_uc(seq) -> str:
Expand All @@ -46,7 +46,7 @@ def make_string_uc(seq) -> str:
"""
if not isinstance(seq, str):
# Remove code from sequence only if it is valid
if make_string(seq[:8]).upper() in ('ASCII', 'UNICODE', 'JIS', ''):
if make_string(seq[:8]).upper() in ('ASCII\0\0\0', 'UNICODE\0', 'JIS\0\0\0\0\0', ''):
seq = seq[8:]
# Of course, this is only correct if ASCII, and the standard explicitly
# allows JIS and Unicode.
Expand Down

0 comments on commit fc178d0

Please sign in to comment.