From 97e534e76b189176bf704098673f33079f68b14a Mon Sep 17 00:00:00 2001 From: Tran Tien Dat Date: Wed, 21 Feb 2018 19:58:29 +0800 Subject: Fix #2829 --- mitmproxy/net/http/cookies.py | 14 +++++++++----- test/mitmproxy/net/http/test_cookies.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/mitmproxy/net/http/cookies.py b/mitmproxy/net/http/cookies.py index 7bef8757..39e8d60f 100644 --- a/mitmproxy/net/http/cookies.py +++ b/mitmproxy/net/http/cookies.py @@ -159,13 +159,17 @@ 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 - if rhs or lhs: + + # as long as there's a "=", we consider it a pair + pairs.append([lhs, rhs]) + + elif lhs: pairs.append([lhs, rhs]) - # comma marks the beginning of a new cookie - if off < len(s) and s[off] == ",": - cookies.append(pairs) - pairs = [] + # comma marks the beginning of a new cookie + if off < len(s) and s[off] == ",": + cookies.append(pairs) + pairs = [] off += 1 diff --git a/test/mitmproxy/net/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py index e12b0f00..74233cca 100644 --- a/test/mitmproxy/net/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -142,6 +142,27 @@ def test_cookie_roundtrips(): def test_parse_set_cookie_pairs(): pairs = [ + [ + "=", + [[ + ["", ""] + ]] + ], + [ + "=;foo=bar", + [[ + ["", ""], + ["foo", "bar"] + ]] + ], + [ + "=;=;foo=bar", + [[ + ["", ""], + ["", ""], + ["foo", "bar"] + ]] + ], [ "=uno", [[ -- cgit v1.2.3 From c471c42c7c2b26b4330c7780abe72cc8176580ab Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 23 Feb 2018 13:04:31 +1300 Subject: Fix an issue with quoting and commands Previously, quotes would disappear during editing, making it impossible to enter command arguments with spaces. --- mitmproxy/tools/console/commander/commander.py | 22 +++++++++++++++++++--- test/mitmproxy/test_command.py | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py index 566c42e6..f3e499f8 100644 --- a/mitmproxy/tools/console/commander/commander.py +++ b/mitmproxy/tools/console/commander/commander.py @@ -68,6 +68,21 @@ class CommandBuffer: else: self._cursor = x + def maybequote(self, value): + if " " in value and not value.startswith("\""): + return "\"%s\"" % value + return value + + def parse_quoted(self, txt): + parts, remhelp = self.master.commands.parse_partial(txt) + for i, p in enumerate(parts): + parts[i] = mitmproxy.command.ParseResult( + value = self.maybequote(p.value), + type = p.type, + valid = p.valid + ) + return parts, remhelp + def render(self): """ This function is somewhat tricky - in order to make the cursor @@ -75,7 +90,7 @@ class CommandBuffer: character-for-character offset match in the rendered output, up to the cursor. Beyond that, we can add stuff. """ - parts, remhelp = self.master.commands.parse_partial(self.text) + parts, remhelp = self.parse_quoted(self.text) ret = [] for p in parts: if p.valid: @@ -95,8 +110,9 @@ class CommandBuffer: return ret def flatten(self, txt): - parts, _ = self.master.commands.parse_partial(txt) - return " ".join([x.value for x in parts]) + parts, _ = self.parse_quoted(txt) + ret = [x.value for x in parts] + return " ".join(ret) def left(self) -> None: self.cursor = self.cursor - 1 diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index c777192d..e2b80753 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -211,6 +211,22 @@ class TestCommand: ], [] ], + [ + "flow \"one two", + [ + command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = "\"one two", type = flow.Flow, valid = False), + ], + ["str"] + ], + [ + "flow \"one two\"", + [ + command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True), + command.ParseResult(value = "one two", type = flow.Flow, valid = False), + ], + ["str"] + ], ] with taddons.context() as tctx: tctx.master.addons.add(TAddon()) -- cgit v1.2.3 From 3c7f41dee6ba74d468b5ae520a3d3f5eee374d92 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 23 Feb 2018 14:25:34 +1300 Subject: Prep for v3.0.1 --- CHANGELOG | 4 ++++ mitmproxy/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6c8fc43b..8f82b1d5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +23 February 2018: mitmproxy 3.0 + + * Fix a quote-related issue affecting the mitmproxy console command prompt + 22 February 2018: mitmproxy 3.0 ** Major Changes ** diff --git a/mitmproxy/version.py b/mitmproxy/version.py index 92b14b9a..a4e2ce37 100644 --- a/mitmproxy/version.py +++ b/mitmproxy/version.py @@ -3,7 +3,7 @@ import subprocess # The actual version string. For precompiled binaries, this will be changed to include the build # tag, e.g. "3.0.0.dev0042-0xcafeabc" -VERSION = "4.0.0" +VERSION = "3.0.1" PATHOD = "pathod " + VERSION MITMPROXY = "mitmproxy " + VERSION -- cgit v1.2.3 From d1ecf9df9431397e5e7e6fee58c7b04c6f37a44b Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sat, 24 Feb 2018 00:26:49 +0800 Subject: Explicitly declare pyperclip requirement pyperclip version 1.6.0 introduces an API change: the class `pyperclip.exceptions.PyperclipException` is moved to `pyperclip.PyperclipException`. As mitmproxy uses the latter, it's better to explicitly declare the requirement. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1f82dbce..8874b574 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ setup( "pyasn1>=0.3.1,<0.5", "pyOpenSSL>=17.5,<17.6", "pyparsing>=2.1.3, <2.3", - "pyperclip>=1.5.22, <1.7", + "pyperclip>=1.6.0, <1.7", "requests>=2.9.1, <3", "ruamel.yaml>=0.13.2, <0.16", "sortedcontainers>=1.5.4, <1.6", -- cgit v1.2.3 From 18384eecbd8fafca87d7ecaa79d366a5df1063e0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 23 Feb 2018 18:14:02 +0100 Subject: bump version again we may have to figure out something smarter here, maybe set the version for tagged commits to whatever the tag is. --- mitmproxy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/version.py b/mitmproxy/version.py index a4e2ce37..92b14b9a 100644 --- a/mitmproxy/version.py +++ b/mitmproxy/version.py @@ -3,7 +3,7 @@ import subprocess # The actual version string. For precompiled binaries, this will be changed to include the build # tag, e.g. "3.0.0.dev0042-0xcafeabc" -VERSION = "3.0.1" +VERSION = "4.0.0" PATHOD = "pathod " + VERSION MITMPROXY = "mitmproxy " + VERSION -- cgit v1.2.3 From dde71ffff7201f10c6f98eb1c855cba1a3ef5ef4 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 24 Feb 2018 09:18:08 +1300 Subject: Fix loss of keyboard control after spawn We were stepping on this Urwid bug: https://github.com/urwid/urwid/issues/285 The guys from pazz/alot found a fix, which I cribbed: https://github.com/pazz/alot/pull/1204 Fix #2901 --- mitmproxy/tools/console/master.py | 47 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index da35047e..76d8724a 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -10,6 +10,7 @@ import sys import tempfile import traceback import typing # noqa +import contextlib import urwid @@ -102,6 +103,16 @@ class ConsoleMaster(master.Master): return callback(*args) self.loop.set_alarm_in(seconds, cb) + @contextlib.contextmanager + def uistopped(self): + self.loop.stop() + try: + yield + finally: + self.loop.start() + self.loop.screen_size = None + self.loop.draw_screen() + def spawn_editor(self, data): text = not isinstance(data, bytes) fd, name = tempfile.mkstemp('', "mproxy", text=text) @@ -111,17 +122,16 @@ class ConsoleMaster(master.Master): c = os.environ.get("EDITOR") or "vi" cmd = shlex.split(c) cmd.append(name) - self.ui.stop() - try: - subprocess.call(cmd) - except: - signals.status_message.send( - message="Can't start editor: %s" % " ".join(c) - ) - else: - with open(name, "r" if text else "rb") as f: - data = f.read() - self.ui.start() + with self.uistopped(): + try: + subprocess.call(cmd) + except: + signals.status_message.send( + message="Can't start editor: %s" % " ".join(c) + ) + else: + with open(name, "r" if text else "rb") as f: + data = f.read() os.unlink(name) return data @@ -153,14 +163,13 @@ class ConsoleMaster(master.Master): c = "less" cmd = shlex.split(c) cmd.append(name) - self.ui.stop() - try: - subprocess.call(cmd, shell=shell) - except: - signals.status_message.send( - message="Can't start external viewer: %s" % " ".join(c) - ) - self.ui.start() + with self.uistopped(): + try: + subprocess.call(cmd, shell=shell) + except: + signals.status_message.send( + message="Can't start external viewer: %s" % " ".join(c) + ) os.unlink(name) def set_palette(self, opts, updated): -- cgit v1.2.3 From 6f2f34981a61de91a8f576a680b5293e5767115d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 24 Feb 2018 09:53:45 +1300 Subject: Tag 3.0.2 --- mitmproxy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/version.py b/mitmproxy/version.py index 92b14b9a..3aa368d4 100644 --- a/mitmproxy/version.py +++ b/mitmproxy/version.py @@ -3,7 +3,7 @@ import subprocess # The actual version string. For precompiled binaries, this will be changed to include the build # tag, e.g. "3.0.0.dev0042-0xcafeabc" -VERSION = "4.0.0" +VERSION = "3.0.2" PATHOD = "pathod " + VERSION MITMPROXY = "mitmproxy " + VERSION -- cgit v1.2.3 From 250ffcc83bbe546ff4c36715c872c55e549e8289 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 24 Feb 2018 10:01:02 +1300 Subject: Bump version Re-bump after tag --- mitmproxy/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/version.py b/mitmproxy/version.py index 3aa368d4..92b14b9a 100644 --- a/mitmproxy/version.py +++ b/mitmproxy/version.py @@ -3,7 +3,7 @@ import subprocess # The actual version string. For precompiled binaries, this will be changed to include the build # tag, e.g. "3.0.0.dev0042-0xcafeabc" -VERSION = "3.0.2" +VERSION = "4.0.0" PATHOD = "pathod " + VERSION MITMPROXY = "mitmproxy " + VERSION -- cgit v1.2.3