diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 24e8e772491..f8253531730 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -532,6 +532,9 @@ class UnicodeTest( self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd') + # Issue #2242: crash on some Windows/MSVC versions + self.assertRaises(UnicodeDecodeError, '+\xc1'.decode, 'utf-7') + def test_codecs_utf8(self): self.assertEqual(u''.encode('utf-8'), '') self.assertEqual(u'\u20ac'.encode('utf-8'), '\xe2\x82\xac') diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a62e92908dc..16d97c34570 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1523,7 +1523,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s, while (s < e) { Py_UNICODE ch; restart: - ch = *s; + ch = (unsigned char) *s; if (inShift) { if ((ch == '-') || !B64CHAR(ch)) {