diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2005-12-17 04:38:31 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2005-12-17 04:38:31 (GMT) |
commit | 835b243c71f5529da95aca5ca78fb9939278cffe (patch) | |
tree | 4ecc532040db92844d5dffc65f2edfce8fc6d449 | |
parent | e3547fd2f7b8246113817841e55fe47556f3f41a (diff) | |
download | cpython-835b243c71f5529da95aca5ca78fb9939278cffe.zip cpython-835b243c71f5529da95aca5ca78fb9939278cffe.tar.gz cpython-835b243c71f5529da95aca5ca78fb9939278cffe.tar.bz2 |
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
just like string codecs.
-rw-r--r-- | Lib/test/test_unicode.py | 24 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 6 |
3 files changed, 20 insertions, 13 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index e298a14..3a9b46c 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -615,20 +615,24 @@ class UnicodeTest( self.assertEqual(u'hello'.encode('latin-1'), 'hello') # Roundtrip safety for BMP (just the first 1024 chars) - u = u''.join(map(unichr, xrange(1024))) - for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', - 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'): - self.assertEqual(unicode(u.encode(encoding),encoding), u) + for c in xrange(1024): + u = unichr(c) + for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', + 'utf-16-be', 'raw_unicode_escape', + 'unicode_escape', 'unicode_internal'): + self.assertEqual(unicode(u.encode(encoding),encoding), u) # Roundtrip safety for BMP (just the first 256 chars) - u = u''.join(map(unichr, xrange(256))) - for encoding in ('latin-1',): - self.assertEqual(unicode(u.encode(encoding),encoding), u) + for c in xrange(256): + u = unichr(c) + for encoding in ('latin-1',): + self.assertEqual(unicode(u.encode(encoding),encoding), u) # Roundtrip safety for BMP (just the first 128 chars) - u = u''.join(map(unichr, xrange(128))) - for encoding in ('ascii',): - self.assertEqual(unicode(u.encode(encoding),encoding), u) + for c in xrange(128): + u = unichr(c) + for encoding in ('ascii',): + self.assertEqual(unicode(u.encode(encoding),encoding), u) # Roundtrip safety for non-BMP (just a few chars) u = u'\U00010001\U00020002\U00030003\U00040004\U00050005' @@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1? Core and builtins ----------------- +- Bug #1379994: Builtin unicode_escape and raw_unicode_escape codec + now encodes backslash correctly. + - Patch #1350409: Work around signal handling bug in Visual Studio 2005. - Bug #1281408: Py_BuildValue now works correct even with unsigned longs diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 9e5e3b4..b850559 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1989,9 +1989,9 @@ PyObject *unicodeescape_string(const Py_UNICODE *s, while (size-- > 0) { Py_UNICODE ch = *s++; - /* Escape quotes */ - if (quotes && - (ch == (Py_UNICODE) PyString_AS_STRING(repr)[1] || ch == '\\')) { + /* Escape quotes and backslashes */ + if ((quotes && + ch == (Py_UNICODE) PyString_AS_STRING(repr)[1]) || ch == '\\') { *p++ = '\\'; *p++ = (char) ch; continue; |