Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f1056723
Commit
f1056723
authored
Oct 19, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19279: UTF-7 decoder no more produces illegal unicode strings.
parent
6ea3c9b2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+29
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+2
-0
No files found.
Lib/test/test_codecs.py
View file @
f1056723
...
...
@@ -611,6 +611,35 @@ class UTF7Test(ReadTest):
]
)
def
test_errors
(
self
):
tests
=
[
(
'a
\
xff
b'
,
u'a
\
ufffd
b'
),
(
'a+IK'
,
u'a
\
ufffd
'
),
(
'a+IK-b'
,
u'a
\
ufffd
b'
),
(
'a+IK,b'
,
u'a
\
ufffd
b'
),
(
'a+IKx'
,
u'a
\
u20ac
\
ufffd
'
),
(
'a+IKx-b'
,
u'a
\
u20ac
\
ufffd
b'
),
(
'a+IKwgr'
,
u'a
\
u20ac
\
ufffd
'
),
(
'a+IKwgr-b'
,
u'a
\
u20ac
\
ufffd
b'
),
(
'a+IKwgr,'
,
u'a
\
u20ac
\
ufffd
'
),
(
'a+IKwgr,-b'
,
u'a
\
u20ac
\
ufffd
-b'
),
(
'a+IKwgrB'
,
u'a
\
u20ac
\
u20ac
\
ufffd
'
),
(
'a+IKwgrB-b'
,
u'a
\
u20ac
\
u20ac
\
ufffd
b'
),
(
'a+/,+IKw-b'
,
u'a
\
ufffd
\
u20ac
b'
),
(
'a+//,+IKw-b'
,
u'a
\
ufffd
\
u20ac
b'
),
(
'a+///,+IKw-b'
,
u'a
\
uffff
\
ufffd
\
u20ac
b'
),
(
'a+////,+IKw-b'
,
u'a
\
uffff
\
ufffd
\
u20ac
b'
),
]
for
raw
,
expected
in
tests
:
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
utf_7_decode
,
raw
,
'strict'
,
True
)
self
.
assertEqual
(
raw
.
decode
(
'utf-7'
,
'replace'
),
expected
)
def
test_nonbmp
(
self
):
self
.
assertEqual
(
u'
\
U000104A0
'
.
encode
(
self
.
encoding
),
'+2AHcoA-'
)
self
.
assertEqual
(
u'
\
ud801
\
udca0
'
.
encode
(
self
.
encoding
),
'+2AHcoA-'
)
self
.
assertEqual
(
'+2AHcoA-'
.
decode
(
self
.
encoding
),
u'
\
U000104A0
'
)
class
UTF16ExTest
(
unittest
.
TestCase
):
def
test_errors
(
self
):
...
...
Misc/NEWS
View file @
f1056723
...
...
@@ -9,6 +9,8 @@ What's New in Python 2.7.6?
Core and Builtins
-----------------
- Issue #19279: UTF-7 decoder no more produces illegal unicode strings.
- Issue #18739: Fix an inconsistency between math.log(n) and math.log(long(n));
the results could be off from one another by a ulp or two.
...
...
Objects/unicodeobject.c
View file @
f1056723
...
...
@@ -1671,6 +1671,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
(
base64buffer
>>
(
base64bits
-
16
));
base64bits
-=
16
;
base64buffer
&=
(
1
<<
base64bits
)
-
1
;
/* clear high bits */
assert
(
outCh
<=
0xffff
);
if
(
surrogate
)
{
/* expecting a second surrogate */
if
(
outCh
>=
0xDC00
&&
outCh
<=
0xDFFF
)
{
...
...
@@ -1737,6 +1738,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
inShift
=
1
;
shiftOutStart
=
p
;
base64bits
=
0
;
base64buffer
=
0
;
}
}
else
if
(
DECODE_DIRECT
(
ch
))
{
/* character decodes as itself */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment