Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
566a2be9
Kaydet (Commit)
566a2be9
authored
Eki 20, 2013
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#18958: Improve error message for json.load(s) while passing a string that starts with a UTF-8 BOM.
üst
a0e768cc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
0 deletions
+19
-0
__init__.py
Lib/json/__init__.py
+2
-0
test_decode.py
Lib/test/test_json/test_decode.py
+14
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/json/__init__.py
Dosyayı görüntüle @
566a2be9
...
...
@@ -313,6 +313,8 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
if
not
isinstance
(
s
,
str
):
raise
TypeError
(
'the JSON object must be str, not {!r}'
.
format
(
s
.
__class__
.
__name__
))
if
s
.
startswith
(
u'
\ufeff
'
):
raise
ValueError
(
"Unexpected UTF-8 BOM (decode using utf-8-sig)"
)
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
Dosyayı görüntüle @
566a2be9
...
...
@@ -77,5 +77,19 @@ class TestDecode:
with
self
.
assertRaisesRegex
(
TypeError
,
msg
):
self
.
json
.
load
(
BytesIO
(
b
'[1,2,3]'
))
def
test_string_with_utf8_bom
(
self
):
# see #18958
bom_json
=
"[1,2,3]"
.
encode
(
'utf-8-sig'
)
.
decode
(
'utf-8'
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
self
.
loads
(
bom_json
)
self
.
assertIn
(
'BOM'
,
str
(
cm
.
exception
))
with
self
.
assertRaises
(
ValueError
)
as
cm
:
self
.
json
.
load
(
StringIO
(
bom_json
))
self
.
assertIn
(
'BOM'
,
str
(
cm
.
exception
))
# make sure that the BOM is not detected in the middle of a string
bom_in_str
=
'"{}"'
.
format
(
''
.
encode
(
'utf-8-sig'
)
.
decode
(
'utf-8'
))
self
.
assertEqual
(
self
.
loads
(
bom_in_str
),
'
\ufeff
'
)
self
.
assertEqual
(
self
.
json
.
load
(
StringIO
(
bom_in_str
)),
'
\ufeff
'
)
class
TestPyDecode
(
TestDecode
,
PyTest
):
pass
class
TestCDecode
(
TestDecode
,
CTest
):
pass
Misc/NEWS
Dosyayı görüntüle @
566a2be9
...
...
@@ -62,6 +62,9 @@ Core and Builtins
Library
-------
-
Issue
#
18958
:
Improve
error
message
for
json
.
load
(
s
)
while
passing
a
string
that
starts
with
a
UTF
-
8
BOM
.
-
Issue
#
19307
:
Improve
error
message
for
json
.
load
(
s
)
while
passing
objects
of
the
wrong
type
.
...
...
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