From 4e9d4b37b38a89c0536f3f2169ed8f8d4b6da206 Mon Sep 17 00:00:00 2001 From: kira0204 Date: Wed, 7 Feb 2018 04:41:12 +0530 Subject: [PATCH] fixing logic --- mitmproxy/net/http/cookies.py | 14 +++++++------- test/mitmproxy/net/http/test_cookies.py | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mitmproxy/net/http/cookies.py b/mitmproxy/net/http/cookies.py index 4824bf56e..32032f5f2 100644 --- a/mitmproxy/net/http/cookies.py +++ b/mitmproxy/net/http/cookies.py @@ -114,12 +114,12 @@ def _read_cookie_pairs(s, off=0): lhs, off = _read_key(s, off) lhs = lhs.lstrip() - if lhs: + if lhs is not None: rhs = None if off < len(s) and s[off] == "=": rhs, off = _read_value(s, off + 1, ";") - - pairs.append([lhs, rhs]) + if rhs or lhs: + pairs.append([lhs, rhs]) off += 1 @@ -143,12 +143,12 @@ def _read_set_cookie_pairs(s: str, off=0) -> Tuple[List[TPairs], int]: lhs, off = _read_key(s, off, ";=,") lhs = lhs.lstrip() - if lhs: + if lhs is not None: rhs = None if off < len(s) and s[off] == "=": rhs, off = _read_value(s, off + 1, ";,") - # Special handliing of attributes + # Special handling of attributes if lhs.lower() == "expires": # 'expires' values can contain commas in them so they need to # be handled separately. @@ -161,8 +161,8 @@ def _read_set_cookie_pairs(s: str, off=0) -> Tuple[List[TPairs], int]: if len(rhs) <= 3: trail, off = _read_value(s, off + 1, ";,") rhs = rhs + "," + trail - - pairs.append([lhs, rhs]) + if rhs or lhs: + pairs.append([lhs, rhs]) # comma marks the beginning of a new cookie if off < len(s) and s[off] == ",": diff --git a/test/mitmproxy/net/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py index 77549d9e6..496f595b2 100644 --- a/test/mitmproxy/net/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -6,6 +6,10 @@ from mitmproxy.net.http import cookies cookie_pairs = [ + [ + "=uno", + [["", "uno"]] + ], [ "", []