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 Sat Feb 06 23:35:24 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 Sat Feb 06 23:35:24 2016 +0530 @@ -210,6 +210,10 @@ C1 = pickle.loads(pickle.dumps(C, protocol=proto)) self.assertEqual(C1.output(), expected_output) + def test_legal_chars(self): + self.assertTrue(bool(cookies._is_legal_key('a'))) + self.assertTrue(not bool(cookies._is_legal_key(','))) + class MorselTests(unittest.TestCase): """Tests for the Morsel object."""