[Python-checkins] cpython (3.3): Issue #20538: UTF-7 incremental decoder produced inconsistant string when

serhiy.storchaka python-checkins at python.org
Sat Feb 8 13:09:12 CET 2014


http://hg.python.org/cpython/rev/8d40d9cee409
changeset: 89032:8d40d9cee409
branch: 3.3
parent: 89025:63f8ea0eeb6d
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Feb 08 14:01:29 2014 +0200
summary:
 Issue #20538: UTF-7 incremental decoder produced inconsistant string when
input was truncated in BASE64 section.
files:
 Lib/test/test_codecs.py | 39 ++++++++++++++++++++++++----
 Misc/NEWS | 3 ++
 Objects/unicodeobject.c | 10 ++++++-
 3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -852,13 +852,40 @@
 
 def test_partial(self):
 self.check_partial(
- "a+-b",
+ 'a+-b\x00c\x80d\u0100e\U00010000f',
 [
- "a",
- "a",
- "a+",
- "a+-",
- "a+-b",
+ 'a',
+ 'a',
+ 'a+',
+ 'a+-',
+ 'a+-b',
+ 'a+-b',
+ 'a+-b',
+ 'a+-b',
+ 'a+-b',
+ 'a+-b\x00',
+ 'a+-b\x00c',
+ 'a+-b\x00c',
+ 'a+-b\x00c',
+ 'a+-b\x00c',
+ 'a+-b\x00c',
+ 'a+-b\x00c\x80',
+ 'a+-b\x00c\x80d',
+ 'a+-b\x00c\x80d',
+ 'a+-b\x00c\x80d',
+ 'a+-b\x00c\x80d',
+ 'a+-b\x00c\x80d',
+ 'a+-b\x00c\x80d\u0100',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e',
+ 'a+-b\x00c\x80d\u0100e\U00010000',
+ 'a+-b\x00c\x80d\u0100e\U00010000f',
 ]
 )
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #20538: UTF-7 incremental decoder produced inconsistant string when
+ input was truncated in BASE64 section.
+
 - Issue #17825: Cursor "^" is correctly positioned for SyntaxError and
 IndentationError.
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4474,8 +4474,16 @@
 /* return state */
 if (consumed) {
 if (inShift) {
+ *consumed = startinpos;
+ if (outpos != shiftOutStart &&
+ PyUnicode_MAX_CHAR_VALUE(unicode) > 127) {
+ PyObject *result = PyUnicode_FromKindAndData(
+ PyUnicode_KIND(unicode), PyUnicode_DATA(unicode),
+ shiftOutStart);
+ Py_DECREF(unicode);
+ unicode = result;
+ }
 outpos = shiftOutStart; /* back off output */
- *consumed = startinpos;
 }
 else {
 *consumed = s-starts;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /