From af7088d7f377ff32e2ff9ab197f6c899a835515d Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 13 Nov 2019 10:17:07 -0500 Subject: [PATCH] Fixed issue introduced by change in the lexer that caused mitmproxy to crash when pressing `:`. --- .../tools/console/commander/commander.py | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py index 0c0430813..ee31e1e9e 100644 --- a/mitmproxy/tools/console/commander/commander.py +++ b/mitmproxy/tools/console/commander/commander.py @@ -89,21 +89,28 @@ class CommandBuffer: """ parts, remhelp = self.parse_quoted(self.text) ret = [] - for p in parts: - if p.valid: - if p.type == mitmproxy.types.Cmd: - ret.append(("commander_command", p.value)) + if parts == []: + # Means we just received the leader, so we need to give a blank + # text to the widget to render or it crashes + ret.append(("text", "")) + ret.append(("text", " ")) + else: + for p in parts: + if p.valid: + if p.type == mitmproxy.types.Cmd: + ret.append(("commander_command", p.value)) + else: + ret.append(("text", p.value)) + elif p.value: + ret.append(("commander_invalid", p.value)) else: - ret.append(("text", p.value)) - elif p.value: - ret.append(("commander_invalid", p.value)) - else: - ret.append(("text", "")) - ret.append(("text", " ")) - if remhelp: - ret.append(("text", " ")) - for v in remhelp: - ret.append(("commander_hint", "%s " % v)) + ret.append(("text", "")) + ret.append(("text", " ")) + if remhelp: + ret.append(("text", " ")) + for v in remhelp: + ret.append(("commander_hint", "%s " % v)) + return ret def flatten(self, txt):