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
81fabdb4
Commit
81fabdb4
authored
Jan 22, 2009
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #4874: Most builtin decoders now reject unicode input.
parent
dd01f8f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
14 deletions
+47
-14
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+31
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_codecsmodule.c
Modules/_codecsmodule.c
+14
-14
No files found.
Lib/test/test_codecs.py
View file @
81fabdb4
...
@@ -1475,6 +1475,36 @@ class WithStmtTest(unittest.TestCase):
...
@@ -1475,6 +1475,36 @@ class WithStmtTest(unittest.TestCase):
info
.
streamwriter
,
'strict'
)
as
srw
:
info
.
streamwriter
,
'strict'
)
as
srw
:
self
.
assertEquals
(
srw
.
read
(),
"
\
xfc
"
)
self
.
assertEquals
(
srw
.
read
(),
"
\
xfc
"
)
class
TypesTest
(
unittest
.
TestCase
):
def
test_decode_unicode
(
self
):
# Most decoders don't accept unicode input
decoders
=
[
codecs
.
utf_7_decode
,
codecs
.
utf_8_decode
,
codecs
.
utf_16_le_decode
,
codecs
.
utf_16_be_decode
,
codecs
.
utf_16_ex_decode
,
codecs
.
utf_32_decode
,
codecs
.
utf_32_le_decode
,
codecs
.
utf_32_be_decode
,
codecs
.
utf_32_ex_decode
,
codecs
.
latin_1_decode
,
codecs
.
ascii_decode
,
codecs
.
charmap_decode
,
]
if
hasattr
(
codecs
,
"mbcs_decode"
):
decoders
.
append
(
codecs
.
mbcs_decode
)
for
decoder
in
decoders
:
self
.
assertRaises
(
TypeError
,
decoder
,
"xxx"
)
def
test_unicode_escape
(
self
):
# Escape-decoding an unicode string is supported ang gives the same
# result as decoding the equivalent ASCII bytes string.
self
.
assertEquals
(
codecs
.
unicode_escape_decode
(
r"\u1234"
),
(
"
\
u1234
"
,
6
))
self
.
assertEquals
(
codecs
.
unicode_escape_decode
(
br"\u1234"
),
(
"
\
u1234
"
,
6
))
self
.
assertEquals
(
codecs
.
raw_unicode_escape_decode
(
r"\u1234"
),
(
"
\
u1234
"
,
6
))
self
.
assertEquals
(
codecs
.
raw_unicode_escape_decode
(
br"\u1234"
),
(
"
\
u1234
"
,
6
))
def
test_main
():
def
test_main
():
support
.
run_unittest
(
support
.
run_unittest
(
...
@@ -1501,6 +1531,7 @@ def test_main():
...
@@ -1501,6 +1531,7 @@ def test_main():
BasicUnicodeTest
,
BasicUnicodeTest
,
CharmapTest
,
CharmapTest
,
WithStmtTest
,
WithStmtTest
,
TypesTest
,
)
)
...
...
Misc/NEWS
View file @
81fabdb4
...
@@ -12,6 +12,8 @@ What's New in Python 3.1 alpha 0
...
@@ -12,6 +12,8 @@ What's New in Python 3.1 alpha 0
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #4874: Most builtin decoders now reject unicode input.
- Issue #4842: Don't allow trailing 'L' when constructing an integer
- Issue #4842: Don't allow trailing 'L' when constructing an integer
from a string.
from a string.
...
...
Modules/_codecsmodule.c
View file @
81fabdb4
...
@@ -258,7 +258,7 @@ utf_7_decode(PyObject *self,
...
@@ -258,7 +258,7 @@ utf_7_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
=
NULL
;
PyObject
*
decoded
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_7_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_7_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
consumed
=
pbuf
.
len
;
...
@@ -281,7 +281,7 @@ utf_8_decode(PyObject *self,
...
@@ -281,7 +281,7 @@ utf_8_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
=
NULL
;
PyObject
*
decoded
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_8_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_8_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
consumed
=
pbuf
.
len
;
...
@@ -305,7 +305,7 @@ utf_16_decode(PyObject *self,
...
@@ -305,7 +305,7 @@ utf_16_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
;
PyObject
*
decoded
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_16_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_16_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -328,7 +328,7 @@ utf_16_le_decode(PyObject *self,
...
@@ -328,7 +328,7 @@ utf_16_le_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
=
NULL
;
PyObject
*
decoded
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_16_le_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_16_le_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
...
@@ -352,7 +352,7 @@ utf_16_be_decode(PyObject *self,
...
@@ -352,7 +352,7 @@ utf_16_be_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
=
NULL
;
PyObject
*
decoded
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_16_be_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_16_be_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
...
@@ -384,7 +384,7 @@ utf_16_ex_decode(PyObject *self,
...
@@ -384,7 +384,7 @@ utf_16_ex_decode(PyObject *self,
int
final
=
0
;
int
final
=
0
;
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zii:utf_16_ex_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zii:utf_16_ex_decode"
,
&
pbuf
,
&
errors
,
&
byteorder
,
&
final
))
&
pbuf
,
&
errors
,
&
byteorder
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -409,7 +409,7 @@ utf_32_decode(PyObject *self,
...
@@ -409,7 +409,7 @@ utf_32_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
;
PyObject
*
decoded
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_32_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_32_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -432,7 +432,7 @@ utf_32_le_decode(PyObject *self,
...
@@ -432,7 +432,7 @@ utf_32_le_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
;
PyObject
*
decoded
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_32_le_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_32_le_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -455,7 +455,7 @@ utf_32_be_decode(PyObject *self,
...
@@ -455,7 +455,7 @@ utf_32_be_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
;
PyObject
*
decoded
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:utf_32_be_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:utf_32_be_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -486,7 +486,7 @@ utf_32_ex_decode(PyObject *self,
...
@@ -486,7 +486,7 @@ utf_32_ex_decode(PyObject *self,
int
final
=
0
;
int
final
=
0
;
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zii:utf_32_ex_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zii:utf_32_ex_decode"
,
&
pbuf
,
&
errors
,
&
byteorder
,
&
final
))
&
pbuf
,
&
errors
,
&
byteorder
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
consumed
=
pbuf
.
len
;
/* This is overwritten unless final is true. */
...
@@ -542,7 +542,7 @@ latin_1_decode(PyObject *self,
...
@@ -542,7 +542,7 @@ latin_1_decode(PyObject *self,
PyObject
*
unicode
;
PyObject
*
unicode
;
const
char
*
errors
=
NULL
;
const
char
*
errors
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|z:latin_1_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|z:latin_1_decode"
,
&
pbuf
,
&
errors
))
&
pbuf
,
&
errors
))
return
NULL
;
return
NULL
;
...
@@ -559,7 +559,7 @@ ascii_decode(PyObject *self,
...
@@ -559,7 +559,7 @@ ascii_decode(PyObject *self,
PyObject
*
unicode
;
PyObject
*
unicode
;
const
char
*
errors
=
NULL
;
const
char
*
errors
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|z:ascii_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|z:ascii_decode"
,
&
pbuf
,
&
errors
))
&
pbuf
,
&
errors
))
return
NULL
;
return
NULL
;
...
@@ -577,7 +577,7 @@ charmap_decode(PyObject *self,
...
@@ -577,7 +577,7 @@ charmap_decode(PyObject *self,
const
char
*
errors
=
NULL
;
const
char
*
errors
=
NULL
;
PyObject
*
mapping
=
NULL
;
PyObject
*
mapping
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zO:charmap_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zO:charmap_decode"
,
&
pbuf
,
&
errors
,
&
mapping
))
&
pbuf
,
&
errors
,
&
mapping
))
return
NULL
;
return
NULL
;
if
(
mapping
==
Py_None
)
if
(
mapping
==
Py_None
)
...
@@ -600,7 +600,7 @@ mbcs_decode(PyObject *self,
...
@@ -600,7 +600,7 @@ mbcs_decode(PyObject *self,
Py_ssize_t
consumed
;
Py_ssize_t
consumed
;
PyObject
*
decoded
=
NULL
;
PyObject
*
decoded
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
*|zi:mbcs_decode"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
y
*|zi:mbcs_decode"
,
&
pbuf
,
&
errors
,
&
final
))
&
pbuf
,
&
errors
,
&
final
))
return
NULL
;
return
NULL
;
consumed
=
pbuf
.
len
;
consumed
=
pbuf
.
len
;
...
...
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