* don't attempt to recover malformed data from str, only from bytes. Fixes #1997
This commit is contained in:
parent
6b4430a8a3
commit
dc7d016538
@ -441,7 +441,7 @@ class NameRecord(object):
|
||||
encoding = self.getEncoding()
|
||||
string = self.string
|
||||
|
||||
if encoding == 'utf_16_be' and len(string) % 2 == 1:
|
||||
if isinstance(string, bytes) and encoding == 'utf_16_be' and len(string) % 2 == 1:
|
||||
# Recover badly encoded UTF-16 strings that have an odd number of bytes:
|
||||
# - If the last byte is zero, drop it. Otherwise,
|
||||
# - If all the odd bytes are zero and all the even bytes are ASCII,
|
||||
|
@ -345,6 +345,11 @@ class NameRecordTest(unittest.TestCase):
|
||||
self.assertEqual("utf_16_be", name.getEncoding())
|
||||
self.assertRaises(UnicodeDecodeError, name.toUnicode)
|
||||
|
||||
def test_toUnicode_singleChar(self):
|
||||
# https://github.com/fonttools/fonttools/issues/1997
|
||||
name = makeName("A", 256, 3, 1, 0x409)
|
||||
self.assertEqual(name.toUnicode(), "A")
|
||||
|
||||
def toXML(self, name):
|
||||
writer = XMLWriter(BytesIO())
|
||||
name.toXML(writer, ttFont=None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user