diff options
-rw-r--r-- | mitmproxy/net/http/cookies.py | 14 | ||||
-rw-r--r-- | 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 4824bf56..32032f5f 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 77549d9e..496f595b 100644 --- a/test/mitmproxy/net/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -7,6 +7,10 @@ from mitmproxy.net.http import cookies cookie_pairs = [ [ + "=uno", + [["", "uno"]] + ], + [ "", [] ], |