[Python-checkins] cpython (2.7): Issue #24848: Fixed yet one bug in UTF-7 decoder. Testing for BASE64 character

serhiy.storchaka python-checkins at python.org
Sat Oct 10 02:33:52 EDT 2015


https://hg.python.org/cpython/rev/ff1366ff2761
changeset: 98636:ff1366ff2761
branch: 2.7
parent: 98626:3ad8a2d34d01
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sat Oct 10 09:33:11 2015 +0300
summary:
 Issue #24848: Fixed yet one bug in UTF-7 decoder. Testing for BASE64 character
was locale depending.
files:
 Lib/test/test_codecs.py | 16 ++++++++--------
 Objects/unicodeobject.c | 5 ++++-
 2 files changed, 12 insertions(+), 9 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
@@ -690,9 +690,9 @@
 
 def test_errors(self):
 tests = [
- ('\xffb', u'\ufffdb'),
- ('a\xffb', u'a\ufffdb'),
- ('a\xff\xffb', u'a\ufffd\ufffdb'),
+ ('\xe1b', u'\ufffdb'),
+ ('a\xe1b', u'a\ufffdb'),
+ ('a\xe1\xe1b', u'a\ufffd\ufffdb'),
 ('a+IK', u'a\ufffd'),
 ('a+IK-b', u'a\ufffdb'),
 ('a+IK,b', u'a\ufffdb'),
@@ -708,8 +708,8 @@
 ('a+//,+IKw-b', u'a\ufffd\u20acb'),
 ('a+///,+IKw-b', u'a\uffff\ufffd\u20acb'),
 ('a+////,+IKw-b', u'a\uffff\ufffd\u20acb'),
- ('a+IKw-b\xff', u'a\u20acb\ufffd'),
- ('a+IKw\xffb', u'a\u20ac\ufffdb'),
+ ('a+IKw-b\xe1', u'a\u20acb\ufffd'),
+ ('a+IKw\xe1b', u'a\u20ac\ufffdb'),
 ]
 for raw, expected in tests:
 try:
@@ -738,16 +738,16 @@
 def test_lone_surrogates(self):
 tests = [
 ('a+2AE-b', u'a\ud801b'),
- ('a+2AE\xffb', u'a\ufffdb'),
+ ('a+2AE\xe1b', u'a\ufffdb'),
 ('a+2AE', u'a\ufffd'),
 ('a+2AEA-b', u'a\ufffdb'),
 ('a+2AH-b', u'a\ufffdb'),
 ('a+IKzYAQ-b', u'a\u20ac\ud801b'),
- ('a+IKzYAQ\xffb', u'a\u20ac\ufffdb'),
+ ('a+IKzYAQ\xe1b', u'a\u20ac\ufffdb'),
 ('a+IKzYAQA-b', u'a\u20ac\ufffdb'),
 ('a+IKzYAd-b', u'a\u20ac\ufffdb'),
 ('a+IKwgrNgB-b', u'a\u20ac\u20ac\ud801b'),
- ('a+IKwgrNgB\xffb', u'a\u20ac\u20ac\ufffdb'),
+ ('a+IKwgrNgB\xe1b', u'a\u20ac\u20ac\ufffdb'),
 ('a+IKwgrNgB', u'a\u20ac\u20ac\ufffd'),
 ('a+IKwgrNgBA-b', u'a\u20ac\u20ac\ufffdb'),
 ]
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1555,7 +1555,10 @@
 /* Is c a base-64 character? */
 
 #define IS_BASE64(c) \
- (isalnum(c) || (c) == '+' || (c) == '/')
+ (((c) >= 'A' && (c) <= 'Z') || \
+ ((c) >= 'a' && (c) <= 'z') || \
+ ((c) >= '0' && (c) <= '9') || \
+ (c) == '+' || (c) == '/')
 
 /* given that c is a base-64 character, what is its base-64 value? */
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

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