]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26302: Correctly identify comma as an invalid character for a cookie (correcti...
authorAnish Shah <anish.shah>
Sun, 7 Feb 2016 00:36:00 +0000 (05:36 +0500)
committerAnish Shah <anish.shah>
Sun, 7 Feb 2016 00:36:00 +0000 (05:36 +0500)
Lib/http/cookies.py
Lib/test/test_http_cookies.py
Misc/NEWS

index fda02b7016bc8f510c7141cc947a6832f470cc73..dbddd6cb8c2a343fe30b47491528c2f6178f5c2c 100644 (file)
@@ -174,7 +174,7 @@ _Translator.update({
     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.
index d3e06a452dec2fe30b56778fde61dc1ba5edd85e..2432e0bf53405708964070dfbe098b19d104ef8d 100644 (file)
@@ -210,6 +210,12 @@ class CookieTests(unittest.TestCase):
                 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."""
index fd4ca59277ca884569b8aa27b5042f867ae70579..a0ccaef865556180996ccf0f4b9f45406767ce5d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
 Core and Builtins
 -----------------
 
+- Issue #26302: Correct behavior to reject comma as a legal character for
+  cookie names.
+
 - Issue #4806: Avoid masking the original TypeError exception when using star
   (*) unpacking in function calls.  Based on patch by Hagen Fürstenau and
   Daniel Urban.