From 68cc3e721f1301779174421a455a30bca6d36206 Mon Sep 17 00:00:00 2001 From: Brad Dixon Date: Mon, 2 Aug 2021 13:18:22 -0400 Subject: [PATCH] Fix #4614 Options and Keybinding screen: home and end crash mitmproxy (#4693) * Fix #4614 Options and Keybinding screen: home and end crash mitmproxy * fix flake8 * Add integration test for fix to #4614 * fix the flake8, again. --- mitmproxy/tools/console/keybindings.py | 7 +++++++ mitmproxy/tools/console/options.py | 7 +++++++ test/mitmproxy/tools/console/test_integration.py | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/mitmproxy/tools/console/keybindings.py b/mitmproxy/tools/console/keybindings.py index 312c19f94..bd8f7de42 100644 --- a/mitmproxy/tools/console/keybindings.py +++ b/mitmproxy/tools/console/keybindings.py @@ -66,6 +66,7 @@ class KeyListWalker(urwid.ListWalker): self.index = index self.focus_obj = self._get(self.index) keybinding_focus_change.send(binding.help or "") + self._modified() def get_next(self, pos): if pos >= len(self.bindings) - 1: @@ -79,6 +80,12 @@ class KeyListWalker(urwid.ListWalker): return None, None return self._get(pos), pos + def positions(self, reverse=False): + if reverse: + return reversed(range(len(self.bindings))) + else: + return range(len(self.bindings)) + class KeyList(urwid.ListBox): def __init__(self, master): diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py index 5e5ef2a68..9b723bb3a 100644 --- a/mitmproxy/tools/console/options.py +++ b/mitmproxy/tools/console/options.py @@ -142,6 +142,7 @@ class OptionListWalker(urwid.ListWalker): self.index = index self.focus_obj = self._get(self.index, self.editing) option_focus_change.send(opt.help) + self._modified() def get_next(self, pos): if pos >= len(self.opts) - 1: @@ -155,6 +156,12 @@ class OptionListWalker(urwid.ListWalker): return None, None return self._get(pos, False), pos + def positions(self, reverse=False): + if reverse: + return reversed(range(len(self.opts))) + else: + return range(len(self.opts)) + class OptionsList(urwid.ListBox): def __init__(self, master): diff --git a/test/mitmproxy/tools/console/test_integration.py b/test/mitmproxy/tools/console/test_integration.py index 21813e0a7..4bc1c0000 100644 --- a/test/mitmproxy/tools/console/test_integration.py +++ b/test/mitmproxy/tools/console/test_integration.py @@ -43,3 +43,11 @@ def test_integration(tdata, console): console.type(f":view.flows.load {tdata.path('mitmproxy/data/dumpfile-7.mitm')}") console.type("") console.type("") # view second flow + + +def test_options_home_end(console): + console.type("O") + + +def test_keybindings_home_end(console): + console.type("K") \ No newline at end of file