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
f249671d
Kaydet (Commit)
f249671d
authored
Mar 13, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23138: Fixed parsing cookies with absent keys or values in cookiejar.
Patch by Demian Brecht.
üst
7c26be5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
15 deletions
+57
-15
cookielib.py
Lib/cookielib.py
+31
-15
test_cookielib.py
Lib/test/test_cookielib.py
+23
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/cookielib.py
Dosyayı görüntüle @
f249671d
...
@@ -464,26 +464,42 @@ def parse_ns_headers(ns_headers):
...
@@ -464,26 +464,42 @@ def parse_ns_headers(ns_headers):
for
ns_header
in
ns_headers
:
for
ns_header
in
ns_headers
:
pairs
=
[]
pairs
=
[]
version_set
=
False
version_set
=
False
for
ii
,
param
in
enumerate
(
re
.
split
(
r";\s*"
,
ns_header
)):
param
=
param
.
rstrip
()
# XXX: The following does not strictly adhere to RFCs in that empty
if
param
==
""
:
continue
# names and values are legal (the former will only appear once and will
if
"="
not
in
param
:
# be overwritten if multiple occurrences are present). This is
k
,
v
=
param
,
None
# mostly to deal with backwards compatibility.
else
:
for
ii
,
param
in
enumerate
(
ns_header
.
split
(
';'
)):
k
,
v
=
re
.
split
(
r"\s*=\s*"
,
param
,
1
)
param
=
param
.
strip
()
k
=
k
.
lstrip
()
key
,
sep
,
val
=
param
.
partition
(
'='
)
key
=
key
.
strip
()
if
not
key
:
if
ii
==
0
:
break
else
:
continue
# allow for a distinction between present and empty and missing
# altogether
val
=
val
.
strip
()
if
sep
else
None
if
ii
!=
0
:
if
ii
!=
0
:
lc
=
k
.
lower
()
lc
=
k
ey
.
lower
()
if
lc
in
known_attrs
:
if
lc
in
known_attrs
:
k
=
lc
key
=
lc
if
k
==
"version"
:
if
key
==
"version"
:
# This is an RFC 2109 cookie.
# This is an RFC 2109 cookie.
v
=
_strip_quotes
(
v
)
if
val
is
not
None
:
val
=
_strip_quotes
(
val
)
version_set
=
True
version_set
=
True
if
k
==
"expires"
:
elif
key
==
"expires"
:
# convert expires date to seconds since epoch
# convert expires date to seconds since epoch
v
=
http2time
(
_strip_quotes
(
v
))
# None if invalid
if
val
is
not
None
:
pairs
.
append
((
k
,
v
))
val
=
http2time
(
_strip_quotes
(
val
))
# None if invalid
pairs
.
append
((
key
,
val
))
if
pairs
:
if
pairs
:
if
not
version_set
:
if
not
version_set
:
...
...
Lib/test/test_cookielib.py
Dosyayı görüntüle @
f249671d
...
@@ -445,6 +445,9 @@ class CookieTests(TestCase):
...
@@ -445,6 +445,9 @@ class CookieTests(TestCase):
interact_netscape
(
c
,
"http://www.acme.com:80/"
,
'foo=bar; expires='
)
interact_netscape
(
c
,
"http://www.acme.com:80/"
,
'foo=bar; expires='
)
interact_netscape
(
c
,
"http://www.acme.com:80/"
,
'spam=eggs; '
interact_netscape
(
c
,
"http://www.acme.com:80/"
,
'spam=eggs; '
'expires="Foo Bar 25 33:22:11 3022"'
)
'expires="Foo Bar 25 33:22:11 3022"'
)
interact_netscape
(
c
,
'http://www.acme.com/'
,
'fortytwo='
)
interact_netscape
(
c
,
'http://www.acme.com/'
,
'=unladenswallow'
)
interact_netscape
(
c
,
'http://www.acme.com/'
,
'holyhandgrenade'
)
cookie
=
c
.
_cookies
[
".acme.com"
][
"/"
][
"spam"
]
cookie
=
c
.
_cookies
[
".acme.com"
][
"/"
][
"spam"
]
self
.
assertEqual
(
cookie
.
domain
,
".acme.com"
)
self
.
assertEqual
(
cookie
.
domain
,
".acme.com"
)
...
@@ -471,6 +474,16 @@ class CookieTests(TestCase):
...
@@ -471,6 +474,16 @@ class CookieTests(TestCase):
self
.
assertIsNone
(
foo
.
expires
)
self
.
assertIsNone
(
foo
.
expires
)
self
.
assertIsNone
(
spam
.
expires
)
self
.
assertIsNone
(
spam
.
expires
)
cookie
=
c
.
_cookies
[
'www.acme.com'
][
'/'
][
'fortytwo'
]
self
.
assertIsNotNone
(
cookie
.
value
)
self
.
assertEqual
(
cookie
.
value
,
''
)
# there should be a distinction between a present but empty value
# (above) and a value that's entirely missing (below)
cookie
=
c
.
_cookies
[
'www.acme.com'
][
'/'
][
'holyhandgrenade'
]
self
.
assertIsNone
(
cookie
.
value
)
def
test_ns_parser_special_names
(
self
):
def
test_ns_parser_special_names
(
self
):
# names such as 'expires' are not special in first name=value pair
# names such as 'expires' are not special in first name=value pair
# of Set-Cookie: header
# of Set-Cookie: header
...
@@ -1092,6 +1105,13 @@ class CookieTests(TestCase):
...
@@ -1092,6 +1105,13 @@ class CookieTests(TestCase):
parse_ns_headers
([
"foo"
]),
parse_ns_headers
([
"foo"
]),
[[(
"foo"
,
None
),
(
"version"
,
"0"
)]]
[[(
"foo"
,
None
),
(
"version"
,
"0"
)]]
)
)
# missing cookie values for parsed attributes
self
.
assertEqual
(
parse_ns_headers
([
'foo=bar; expires'
]),
[[(
'foo'
,
'bar'
),
(
'expires'
,
None
),
(
'version'
,
'0'
)]])
self
.
assertEqual
(
parse_ns_headers
([
'foo=bar; version'
]),
[[(
'foo'
,
'bar'
),
(
'version'
,
None
)]])
# shouldn't add version if header is empty
# shouldn't add version if header is empty
self
.
assertEqual
(
parse_ns_headers
([
""
]),
[])
self
.
assertEqual
(
parse_ns_headers
([
""
]),
[])
...
@@ -1106,6 +1126,8 @@ class CookieTests(TestCase):
...
@@ -1106,6 +1126,8 @@ class CookieTests(TestCase):
c
.
extract_cookies
(
r
,
req
)
c
.
extract_cookies
(
r
,
req
)
return
c
return
c
future
=
cookielib
.
time2netscape
(
time
.
time
()
+
3600
)
# none of these bad headers should cause an exception to be raised
# none of these bad headers should cause an exception to be raised
for
headers
in
[
for
headers
in
[
[
"Set-Cookie: "
],
# actually, nothing wrong with this
[
"Set-Cookie: "
],
# actually, nothing wrong with this
...
@@ -1116,6 +1138,7 @@ class CookieTests(TestCase):
...
@@ -1116,6 +1138,7 @@ class CookieTests(TestCase):
[
"Set-Cookie: b=foo; max-age=oops"
],
[
"Set-Cookie: b=foo; max-age=oops"
],
# bad version
# bad version
[
"Set-Cookie: b=foo; version=spam"
],
[
"Set-Cookie: b=foo; version=spam"
],
[
"Set-Cookie:; Expires=
%
s"
%
future
],
]:
]:
c
=
cookiejar_from_cookie_headers
(
headers
)
c
=
cookiejar_from_cookie_headers
(
headers
)
# these bad cookies shouldn't be set
# these bad cookies shouldn't be set
...
...
Misc/NEWS
Dosyayı görüntüle @
f249671d
...
@@ -21,6 +21,9 @@ Core and Builtins
...
@@ -21,6 +21,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #23138: Fixed parsing cookies with absent keys or values in cookiejar.
Patch by Demian Brecht.
- Issue #23051: multiprocessing.Pool methods imap() and imap_unordered() now
- Issue #23051: multiprocessing.Pool methods imap() and imap_unordered() now
handle exceptions raised by an iterator. Patch by Alon Diamant and Davin
handle exceptions raised by an iterator. Patch by Alon Diamant and Davin
Potts.
Potts.
...
...
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