diff -r 80c7d63325f6 Lib/http/cookies.py --- a/Lib/http/cookies.py Wed Jun 29 13:44:05 2011 +0200 +++ b/Lib/http/cookies.py Wed Jun 29 14:40:06 2011 +0100 @@ -552,8 +552,12 @@ M[key] = _unquote(value) else: rval, cval = self.value_decode(value) - self.__set(key, rval, cval) - M = self[key] + try: + self.__set(key, rval, cval) + M = self[key] + except CookieError: + # Postel's law. + pass class SimpleCookie(BaseCookie): diff -r 80c7d63325f6 Lib/test/test_http_cookies.py --- a/Lib/test/test_http_cookies.py Wed Jun 29 13:44:05 2011 +0200 +++ b/Lib/test/test_http_cookies.py Wed Jun 29 14:40:06 2011 +0100 @@ -77,6 +77,19 @@ self.assertEqual(C.output(['val']), 'Set-Cookie: val="some\054円funky\073円stuff"') + def test_illegal_names(self): + # Issue 2193: various servers/browsers use/support cookies with ':' in + # the name (RFC2109 notwithstanding). We should deal with them + # gracefully. This means we silently ignore when loading, but raise + # exception when setting in other situations. + + C = cookies.SimpleCookie() + self.assertRaises(cookies.CookieError, + C.__setitem__, 'invalid:name', 'a value') + + C.load('invalid:name=value1; validname=value2') + self.assertEqual(repr(C), "") + def test_special_attrs(self): # 'expires' C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')

AltStyle によって変換されたページ (->オリジナル) /