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
78edf757
Commit
78edf757
authored
Nov 15, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Issue #13333: The UTF-7 decoder now accepts lone surrogates
(the encoder already accepts them).
parents
9a812cbc
5418ee0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+12
-4
Misc/NEWS
Misc/NEWS
+3
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+7
-9
No files found.
Lib/test/test_unicode.py
View file @
78edf757
...
@@ -1108,10 +1108,18 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -1108,10 +1108,18 @@ class UnicodeTest(string_tests.CommonTest,
for (x, y) in utfTests:
for (x, y) in utfTests:
self.assertEqual(x.encode('
utf
-
7
'), y)
self.assertEqual(x.encode('
utf
-
7
'), y)
# Unpaired surrogates not supported
# Unpaired surrogates are passed through
self.assertRaises(UnicodeError, str, b'
+
3
ADYAA
-
', '
utf
-
7
')
self.assertEqual('
\
uD801
'.encode('
utf
-
7
'), b'
+
2
AE
-
')
self.assertEqual('
\
uD801x
'.encode('
utf
-
7
'), b'
+
2
AE
-
x
')
self.assertEqual(str(b'
+
3
ADYAA
-
', '
utf
-
7
', '
replace
'), '
\
ufffd
\
ufffd
')
self.assertEqual('
\
uDC01
'.encode('
utf
-
7
'), b'
+
3
AE
-
')
self.assertEqual('
\
uDC01x
'.encode('
utf
-
7
'), b'
+
3
AE
-
x
')
self.assertEqual(b'
+
2
AE
-
'.decode('
utf
-
7
'), '
\
uD801
')
self.assertEqual(b'
+
2
AE
-
x
'.decode('
utf
-
7
'), '
\
uD801x
')
self.assertEqual(b'
+
3
AE
-
'.decode('
utf
-
7
'), '
\
uDC01
')
self.assertEqual(b'
+
3
AE
-
x
'.decode('
utf
-
7
'), '
\
uDC01x
')
self.assertEqual('
\
uD801
\
U000abcde
'.encode('
utf
-
7
'), b'
+
2
AHab9ze
-
')
self.assertEqual(b'
+
2
AHab9ze
-
'.decode('
utf
-
7
'), '
\
uD801
\
U000abcde
')
# Issue #2242: crash on some Windows/MSVC versions
# Issue #2242: crash on some Windows/MSVC versions
self.assertEqual(b'
+
\
xc1
'.decode('
utf
-
7
'), '
\
xc1
')
self.assertEqual(b'
+
\
xc1
'.decode('
utf
-
7
'), '
\
xc1
')
...
...
Misc/NEWS
View file @
78edf757
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder
already accepts them).
- Issue #13389: Full garbage collection passes now clear the freelists for
- Issue #13389: Full garbage collection passes now clear the freelists for
list and dict objects. They already cleared other freelists in the
list and dict objects. They already cleared other freelists in the
interpreter.
interpreter.
...
...
Objects/unicodeobject.c
View file @
78edf757
...
@@ -3884,21 +3884,18 @@ PyUnicode_DecodeUTF7Stateful(const char *s,
...
@@ -3884,21 +3884,18 @@ PyUnicode_DecodeUTF7Stateful(const char *s,
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
ch2
)
<
0
)
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
ch2
)
<
0
)
goto
onError
;
goto
onError
;
surrogate
=
0
;
surrogate
=
0
;
continue
;
}
}
else
{
else
{
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
surrogate
)
<
0
)
goto
onError
;
surrogate
=
0
;
surrogate
=
0
;
errmsg
=
"second surrogate missing"
;
goto
utf7Error
;
}
}
}
}
else
if
(
outCh
>=
0xD800
&&
outCh
<=
0xDBFF
)
{
if
(
outCh
>=
0xD800
&&
outCh
<=
0xDBFF
)
{
/* first surrogate */
/* first surrogate */
surrogate
=
outCh
;
surrogate
=
outCh
;
}
}
else
if
(
outCh
>=
0xDC00
&&
outCh
<=
0xDFFF
)
{
errmsg
=
"unexpected second surrogate"
;
goto
utf7Error
;
}
else
{
else
{
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
outCh
)
<
0
)
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
outCh
)
<
0
)
goto
onError
;
goto
onError
;
...
@@ -3909,8 +3906,9 @@ PyUnicode_DecodeUTF7Stateful(const char *s,
...
@@ -3909,8 +3906,9 @@ PyUnicode_DecodeUTF7Stateful(const char *s,
inShift
=
0
;
inShift
=
0
;
s
++
;
s
++
;
if
(
surrogate
)
{
if
(
surrogate
)
{
errmsg
=
"second surrogate missing at end of shift sequence"
;
if
(
unicode_putchar
(
&
unicode
,
&
outpos
,
surrogate
)
<
0
)
goto
utf7Error
;
goto
onError
;
surrogate
=
0
;
}
}
if
(
base64bits
>
0
)
{
/* left-over bits */
if
(
base64bits
>
0
)
{
/* left-over bits */
if
(
base64bits
>=
6
)
{
if
(
base64bits
>=
6
)
{
...
...
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