diff -r 5873cfb42ebe Lib/http/cookies.py --- a/Lib/http/cookies.py Tue Feb 02 17:04:56 2016 -0600 +++ b/Lib/http/cookies.py Sun Feb 07 15:50:53 2016 +0530 @@ -174,7 +174,7 @@ ord('\\'): '\\\\', }) -_is_legal_key = re.compile('[%s]+' % _LegalChars).fullmatch +_is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch def _quote(str): r"""Quote a string for use in a cookie header. diff -r 5873cfb42ebe Lib/test/test_http_cookies.py --- a/Lib/test/test_http_cookies.py Tue Feb 02 17:04:56 2016 -0600 +++ b/Lib/test/test_http_cookies.py Sun Feb 07 15:50:53 2016 +0530 @@ -210,6 +210,12 @@ C1 = pickle.loads(pickle.dumps(C, protocol=proto)) self.assertEqual(C1.output(), expected_output) + def test_illegal_chars(self): + rawdata = "a=b; c,d=e" + C = cookies.SimpleCookie() + with self.assertRaises(cookies.CookieError): + C.load(rawdata) + class MorselTests(unittest.TestCase): """Tests for the Morsel object."""