Bug #1572832: fix a bug in ISO-2022 codecs which may cause segfault

when encoding non-BMP unicode characters.  (Submitted by Ray Chason)
This commit is contained in:
Hye-Shik Chang 2006-10-08 13:48:34 +00:00
parent 846f73a530
commit b788346573
3 changed files with 35 additions and 14 deletions

View file

@ -208,6 +208,16 @@ class Test_ISO2022(unittest.TestCase):
e = u'\u3406'.encode(encoding)
self.failIf(filter(lambda x: x >= '\x80', e))
def test_bug1572832(self):
if sys.maxunicode >= 0x10000:
myunichr = unichr
else:
myunichr = lambda x: unichr(0xD7C0+(x>>10)) + unichr(0xDC00+(x&0x3FF))
for x in xrange(0x10000, 0x110000):
# Any ISO 2022 codec will cause the segfault
myunichr(x).encode('iso_2022_jp', 'ignore')
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test_MultibyteCodec))