Forgot to attach ticket number.

https://fedorahosted.org/freeipa/ticket/5709
--
Petr Vobornik
From fc053d348a9414716af7794baa4300209548a4e3 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Tue, 2 Feb 2016 17:04:47 +0100
Subject: [PATCH] cookie parser: do not fail on cookie with empty value

https://fedorahosted.org/freeipa/ticket/5709
---
 ipapython/cookie.py                    |  3 ++-
 ipatests/test_ipapython/test_cookie.py | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/ipapython/cookie.py b/ipapython/cookie.py
index b44522157ffa6981b5415fb4db7717742c1f5717..89c3e3cd6c430b636cd1a4cae40b3671bec9e44c 100644
--- a/ipapython/cookie.py
+++ b/ipapython/cookie.py
@@ -272,8 +272,9 @@ class Cookie(object):
             if match:
                 key = match.group(1)
                 value = match.group(2)
+
                 # Double quoted value?
-                if value[0] == '"':
+                if value and value[0] == '"':
                     if value[-1] == '"':
                         value = value[1:-1]
                     else:
diff --git a/ipatests/test_ipapython/test_cookie.py b/ipatests/test_ipapython/test_cookie.py
index 97cb79a07b067e18f9195c14703e537595f2fb9d..6af447984d7a9a00b3c5636698d43b7cf1221486 100644
--- a/ipatests/test_ipapython/test_cookie.py
+++ b/ipatests/test_ipapython/test_cookie.py
@@ -50,6 +50,22 @@ class TestParse(unittest.TestCase):
         with self.assertRaises(ValueError):
             cookies = Cookie.parse(s)
 
+        # 1 cookie with empty value
+        s = 'color='
+        cookies = Cookie.parse(s)
+        self.assertEqual(len(cookies), 1)
+        cookie = cookies[0]
+        self.assertEqual(cookie.key, 'color')
+        self.assertEqual(cookie.value, '')
+        self.assertEqual(cookie.domain, None)
+        self.assertEqual(cookie.path, None)
+        self.assertEqual(cookie.max_age, None)
+        self.assertEqual(cookie.expires, None)
+        self.assertEqual(cookie.secure, None)
+        self.assertEqual(cookie.httponly, None)
+        self.assertEqual(str(cookie), "color=")
+        self.assertEqual(cookie.http_cookie(), "color=;")
+
         # 1 cookie with name/value
         s = 'color=blue'
         cookies = Cookie.parse(s)
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to