@@ -479,6 +479,9 @@ def test_ns_parser(self):
479479 interact_netscape (c , "http://www.acme.com:80/" , 'foo=bar; expires=' )
480480 interact_netscape (c , "http://www.acme.com:80/" , 'spam=eggs; '
481481 'expires="Foo Bar 25 33:22:11 3022"' )
482+ interact_netscape (c , 'http://www.acme.com/' , 'fortytwo=' )
483+ interact_netscape (c , 'http://www.acme.com/' , '=unladenswallow' )
484+ interact_netscape (c , 'http://www.acme.com/' , 'holyhandgrenade' )
482485
483486 cookie = c ._cookies [".acme.com" ]["/" ]["spam" ]
484487 self .assertEqual (cookie .domain , ".acme.com" )
@@ -505,6 +508,16 @@ def test_ns_parser(self):
505508 self .assertIsNone (foo .expires )
506509 self .assertIsNone (spam .expires )
507510
511+ cookie = c ._cookies ['www.acme.com' ]['/' ]['fortytwo' ]
512+ self .assertIsNotNone (cookie .value )
513+ self .assertEqual (cookie .value , '' )
514+
515+ # there should be a distinction between a present but empty value
516+ # (above) and a value that's entirely missing (below)
517+
518+ cookie = c ._cookies ['www.acme.com' ]['/' ]['holyhandgrenade' ]
519+ self .assertIsNone (cookie .value )
520+
508521 def test_ns_parser_special_names (self ):
509522 # names such as 'expires' are not special in first name=value pair
510523 # of Set-Cookie: header
@@ -1080,6 +1093,13 @@ def test_parse_ns_headers(self):
10801093 parse_ns_headers (["foo" ]),
10811094 [[("foo" , None ), ("version" , "0" )]]
10821095 )
1096+ # missing cookie values for parsed attributes
1097+ self .assertEqual (
1098+ parse_ns_headers (['foo=bar; expires' ]),
1099+ [[('foo' , 'bar' ), ('expires' , None ), ('version' , '0' )]])
1100+ self .assertEqual (
1101+ parse_ns_headers (['foo=bar; version' ]),
1102+ [[('foo' , 'bar' ), ('version' , None )]])
10831103 # shouldn't add version if header is empty
10841104 self .assertEqual (parse_ns_headers (["" ]), [])
10851105
@@ -1092,6 +1112,8 @@ def cookiejar_from_cookie_headers(headers):
10921112 c .extract_cookies (r , req )
10931113 return c
10941114
1115+ future = time2netscape (time .time ()+ 3600 )
1116+
10951117 # none of these bad headers should cause an exception to be raised
10961118 for headers in [
10971119 ["Set-Cookie: " ], # actually, nothing wrong with this
@@ -1102,6 +1124,7 @@ def cookiejar_from_cookie_headers(headers):
11021124 ["Set-Cookie: b=foo; max-age=oops" ],
11031125 # bad version
11041126 ["Set-Cookie: b=foo; version=spam" ],
1127+ ["Set-Cookie:; Expires=%s" % future ],
11051128 ]:
11061129 c = cookiejar_from_cookie_headers (headers )
11071130 # these bad cookies shouldn't be set
0 commit comments