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
a0e768cc
Commit
a0e768cc
authored
Oct 21, 2013
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19307: Improve error message for json.load(s) while passing objects of the wrong type.
parent
4ea16e56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
1 deletion
+14
-1
Lib/json/__init__.py
Lib/json/__init__.py
+3
-0
Lib/test/test_json/test_decode.py
Lib/test/test_json/test_decode.py
+8
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/json/__init__.py
View file @
a0e768cc
...
...
@@ -310,6 +310,9 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
The ``encoding`` argument is ignored and deprecated.
"""
if
not
isinstance
(
s
,
str
):
raise
TypeError
(
'the JSON object must be str, not {!r}'
.
format
(
s
.
__class__
.
__name__
))
if
(
cls
is
None
and
object_hook
is
None
and
parse_int
is
None
and
parse_float
is
None
and
parse_constant
is
None
and
object_pairs_hook
is
None
and
not
kw
):
...
...
Lib/test/test_json/test_decode.py
View file @
a0e768cc
import
decimal
from
io
import
StringIO
from
io
import
StringIO
,
BytesIO
from
collections
import
OrderedDict
from
test.test_json
import
PyTest
,
CTest
...
...
@@ -70,5 +70,12 @@ class TestDecode:
msg
=
'escape'
self
.
assertRaisesRegex
(
ValueError
,
msg
,
self
.
loads
,
s
)
def
test_invalid_input_type
(
self
):
msg
=
'the JSON object must be str'
for
value
in
[
1
,
3.14
,
b'bytes'
,
b'
\
xff
\
x00
'
,
[],
{},
None
]:
self
.
assertRaisesRegex
(
TypeError
,
msg
,
self
.
loads
,
value
)
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
self
.
json
.
load
(
BytesIO
(
b'[1,2,3]'
))
class
TestPyDecode
(
TestDecode
,
PyTest
):
pass
class
TestCDecode
(
TestDecode
,
CTest
):
pass
Misc/NEWS
View file @
a0e768cc
...
...
@@ -62,6 +62,9 @@ Core and Builtins
Library
-------
-
Issue
#
19307
:
Improve
error
message
for
json
.
load
(
s
)
while
passing
objects
of
the
wrong
type
.
-
Issue
#
16038
:
CVE
-
2013
-
1752
:
ftplib
:
Limit
amount
of
data
read
by
limiting
the
call
to
readline
().
Original
patch
by
Micha
ł
Jastrz
ę
bski
and
Giampaolo
Rodola
.
...
...
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