@@ -984,7 +984,7 @@ def set_ok_path(self, cookie, request):
984984 req_path = request_path (request )
985985 if ((cookie .version > 0 or
986986 (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 )):
988988 _debug (" path attribute %s is not a prefix of request "
989989 "path %s" , cookie .path , req_path )
990990 return False
@@ -1139,6 +1139,11 @@ def return_ok_domain(self, cookie, request):
11391139 req_host , erhn = eff_request_host (request )
11401140 domain = cookie .domain
11411141
1142+ if domain and not domain .startswith ("." ):
1143+ dotdomain = "." + domain
1144+ else :
1145+ dotdomain = domain
1146+
11421147 # strict check of non-domain cookies: Mozilla does this, MSIE5 doesn't
11431148 if (cookie .version == 0 and
11441149 (self .strict_ns_domain & self .DomainStrictNonDomain ) and
@@ -1151,7 +1156,7 @@ def return_ok_domain(self, cookie, request):
11511156 _debug (" effective request-host name %s does not domain-match "
11521157 "RFC 2965 cookie domain %s" , erhn , domain )
11531158 return False
1154- if cookie .version == 0 and not ("." + erhn ).endswith (domain ):
1159+ if cookie .version == 0 and not ("." + erhn ).endswith (dotdomain ):
11551160 _debug (" request-host %s does not match Netscape cookie domain "
11561161 "%s" , req_host , domain )
11571162 return False
@@ -1165,7 +1170,11 @@ def domain_return_ok(self, domain, request):
11651170 req_host = "." + req_host
11661171 if not erhn .startswith ("." ):
11671172 erhn = "." + erhn
1168- if not (req_host .endswith (domain ) or erhn .endswith (domain )):
1173+ if domain and not domain .startswith ("." ):
1174+ dotdomain = "." + domain
1175+ else :
1176+ dotdomain = domain
1177+ if not (req_host .endswith (dotdomain ) or erhn .endswith (dotdomain )):
11691178 #_debug(" request domain %s does not match cookie domain %s",
11701179 # req_host, domain)
11711180 return False
@@ -1182,11 +1191,15 @@ def domain_return_ok(self, domain, request):
11821191 def path_return_ok (self , path , request ):
11831192 _debug ("- checking cookie path=%s" , path )
11841193 req_path = request_path (request )
1185- if not req_path .startswith (path ):
1186- _debug (" %s does not path-match %s" , req_path , path )
1187- return False
1188- 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
11891200
1201+ _debug (" %s does not path-match %s" , req_path , path )
1202+ return False
11901203
11911204def vals_sorted_by_key (adict ):
11921205 keys = adict .keys ()
0 commit comments