A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/ee15aa2b8501718cb77e339381f72409a416f801 below:

Fix path check in cookiejar. (GH-11436) (GH-13427) · python/cpython@ee15aa2 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+41

-5

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+41

-5

lines changed Original file line number Diff line number Diff line change

@@ -984,7 +984,7 @@ def set_ok_path(self, cookie, request):

984 984

req_path = request_path(request)

985 985

if ((cookie.version > 0 or

986 986

(cookie.version == 0 and self.strict_ns_set_path)) and

987 -

not req_path.startswith(cookie.path)):

987 +

not self.path_return_ok(cookie.path, request)):

988 988

_debug(" path attribute %s is not a prefix of request "

989 989

"path %s", cookie.path, req_path)

990 990

return False

@@ -1191,11 +1191,15 @@ def domain_return_ok(self, domain, request):

1191 1191

def path_return_ok(self, path, request):

1192 1192

_debug("- checking cookie path=%s", path)

1193 1193

req_path = request_path(request)

1194 -

if not req_path.startswith(path):

1195 -

_debug(" %s does not path-match %s", req_path, path)

1196 -

return False

1197 -

return True

1194 +

pathlen = len(path)

1195 +

if req_path == path:

1196 +

return True

1197 +

elif (req_path.startswith(path) and

1198 +

(path.endswith("/") or req_path[pathlen:pathlen+1] == "/")):

1199 +

return True

1198 1200 1201 +

_debug(" %s does not path-match %s", req_path, path)

1202 +

return False

1199 1203 1200 1204

def vals_sorted_by_key(adict):

1201 1205

keys = adict.keys()

Original file line number Diff line number Diff line change

@@ -649,6 +649,35 @@ def test_request_path(self):

649 649

req = Request("http://www.example.com")

650 650

self.assertEqual(request_path(req), "/")

651 651 652 +

def test_path_prefix_match(self):

653 +

from cookielib import CookieJar, DefaultCookiePolicy

654 +

from urllib2 import Request

655 + 656 +

pol = DefaultCookiePolicy()

657 +

strict_ns_path_pol = DefaultCookiePolicy(strict_ns_set_path=True)

658 + 659 +

c = CookieJar(pol)

660 +

base_url = "http://bar.com"

661 +

interact_netscape(c, base_url, 'spam=eggs; Path=/foo')

662 +

cookie = c._cookies['bar.com']['/foo']['spam']

663 + 664 +

for path, ok in [('/foo', True),

665 +

('/foo/', True),

666 +

('/foo/bar', True),

667 +

('/', False),

668 +

('/foobad/foo', False)]:

669 +

url = '{0}{1}'.format(base_url, path)

670 +

req = Request(url)

671 +

h = interact_netscape(c, url)

672 +

if ok:

673 +

self.assertIn('spam=eggs', h,

674 +

"cookie not set for {0}".format(path))

675 +

self.assertTrue(strict_ns_path_pol.set_ok_path(cookie, req))

676 +

else:

677 +

self.assertNotIn('spam=eggs', h,

678 +

"cookie set for {0}".format(path))

679 +

self.assertFalse(strict_ns_path_pol.set_ok_path(cookie, req))

680 + 652 681

def test_request_port(self):

653 682

from urllib2 import Request

654 683

from cookielib import request_port, DEFAULT_HTTP_PORT

Original file line number Diff line number Diff line change

@@ -0,0 +1,3 @@

1 +

Don't set cookie for a request when the request path is a prefix match of

2 +

the cookie's path attribute but doesn't end with "/". Patch by Karthikeyan

3 +

Singaravelan.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4