From 504de6bd2c3a0b717e1192eac2435808ab971c5a Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Mon, 6 Oct 2003 05:08:26 +0000 Subject: [PATCH] Fix for SF bug [ 817156 ] invalid \U escape gives 0=length unistr. --- Lib/test/test_unicode.py | 7 +++++++ Objects/unicodeobject.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 6e40b9faf3..18a2d46ba9 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -33,6 +33,13 @@ class UnicodeTest( self.assertEqual(realresult, result) self.assert_(object is not realresult) + def test_literals(self): + self.assertEqual(u'\xff', u'\u00ff') + self.assertEqual(u'\uffff', u'\U0000ffff') + self.assertRaises(UnicodeError, eval, 'u\'\\Ufffffffe\'') + self.assertRaises(UnicodeError, eval, 'u\'\\Uffffffff\'') + self.assertRaises(UnicodeError, eval, 'u\'\\U%08x\'' % 0x110000) + def test_repr(self): if not sys.platform.startswith('java'): # Test basic sanity of repr() diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 83104d802f..f0480fbba7 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1750,7 +1750,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s, chr += 10 + c - 'A'; } s += i; - if (chr == 0xffffffff) + if (chr == 0xffffffff && PyErr_Occurred()) /* _decoding_error will have already written into the target buffer. */ break; -- 2.50.1