mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Fix for UnicodeDecodeError in TiffImagePlugin
Fix for UnicodeDecodeError: ascii codec cannot decode byte while saving a TIFF image Problem occured while saving TIFF images that contain non-ascii characters in metadata Manually merged with master by wiredfool
This commit is contained in:
parent
525f47a64f
commit
42b5a85cb4
|
@ -550,6 +550,8 @@ class ImageFileDirectory(collections.MutableMapping):
|
|||
# contains a 7-bit ASCII code; the last byte must be
|
||||
# NUL (binary zero). Also, I don't think this was well
|
||||
# exercised before.
|
||||
if sys.version_info[0] == 2:
|
||||
value = value.decode('ascii','replace')
|
||||
data = value = b"" + value.encode('ascii', 'replace') + b"\0"
|
||||
else:
|
||||
# integer data
|
||||
|
|
|
@ -15,7 +15,8 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
|
||||
img = hopper()
|
||||
|
||||
textdata = "This is some arbitrary metadata for a text field"
|
||||
basetextdata = "This is some arbitrary metadata for a text field"
|
||||
textdata = basetextdata + " \xff"
|
||||
floatdata = 12.345
|
||||
doubledata = 67.89
|
||||
|
||||
|
@ -35,8 +36,8 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
|
||||
loaded = Image.open(f)
|
||||
|
||||
self.assertEqual(loaded.tag[50838], (len(textdata),))
|
||||
self.assertEqual(loaded.tag[50839], textdata)
|
||||
self.assertEqual(loaded.tag[50838], (len(basetextdata + " ?"),))
|
||||
self.assertEqual(loaded.tag[50839], basetextdata + " ?")
|
||||
self.assertAlmostEqual(loaded.tag[tag_ids['RollAngle']][0], floatdata,
|
||||
places=5)
|
||||
self.assertAlmostEqual(loaded.tag[tag_ids['YawAngle']][0], doubledata)
|
||||
|
|
Loading…
Reference in New Issue
Block a user