Commit 721ccbeb by Craig Heffner

Fixed bug introduced by opening magic files as UTF-8.

parent a14acb7a
...@@ -790,6 +790,8 @@ class Magic(object): ...@@ -790,6 +790,8 @@ class Magic(object):
Returns None. Returns None.
''' '''
# Open file as UTF-8 to prevent decoding issues for non-ASCII bytes
# that may inadvertantly be in the signature file.
fp = codecs.open(fname, "r", encoding='utf-8') fp = codecs.open(fname, "r", encoding='utf-8')
lines = fp.readlines() lines = fp.readlines()
self.parse(lines) self.parse(lines)
...@@ -806,6 +808,8 @@ class Magic(object): ...@@ -806,6 +808,8 @@ class Magic(object):
signature = None signature = None
for line in lines: for line in lines:
# The signature lines were read in as UTF-8 unicode; be sure to treat them as strings.
line = str(line)
# Split at the first comment delimiter (if any) and strip the result # Split at the first comment delimiter (if any) and strip the result
line = line.split('#')[0].strip() line = line.split('#')[0].strip()
# Ignore blank lines and lines that are nothing but comments. # Ignore blank lines and lines that are nothing but comments.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment