aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/console/flowview.py14
-rw-r--r--test/test_console_contentview.py21
2 files changed, 29 insertions, 6 deletions
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py
index b0931fa2..35fc1e43 100644
--- a/libmproxy/console/flowview.py
+++ b/libmproxy/console/flowview.py
@@ -323,21 +323,25 @@ class FlowView(common.WWrap):
return "search hit BOTTOM, continuing at TOP"
def search_get_start(self, search_string):
+ start_line = 0
+ start_index = 0
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
if search_string == last_search_string:
start_line = self.state.get_flow_setting(self.flow, "last_find_line")
start_index = self.state.get_flow_setting(self.flow,
"last_search_index")
- if start_index != None:
- start_index += len(search_string)
- else:
+ if start_index == None:
start_index = 0
+ else:
+ start_index += len(search_string)
+
+ if start_line == None:
+ start_line = 0
+
else:
self.state.add_flow_setting(self.flow, "last_search_string",
search_string)
- start_line = 0
- start_index = 0
return (start_line, start_index)
diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py
index d013d10d..f581424b 100644
--- a/test/test_console_contentview.py
+++ b/test/test_console_contentview.py
@@ -295,7 +295,6 @@ def test_search_highlights_multi_line():
# should highlight second line, first appearance of string.
f.search("string")
text_object = tutils.get_body_line(f.last_displayed_body, 1)
- print text_object.get_text()
assert text_object.get_text() == ('string is string', [(None, 0), (f.highlight_color, 6)])
# should highlight third line, second appearance of string.
@@ -328,4 +327,24 @@ def test_search_focuses():
text_object = tutils.get_body_line(f.last_displayed_body, 1)
assert f.last_displayed_body.focus == text_object
+def test_search_does_not_crash_on_bad():
+ """
+ this used to crash, kept for reference.
+ """
+
+ f = tutils.tflowview(request_contents="this is string\nstring is string\n"+("A" * cv.VIEW_CUTOFF)+"AFTERCUTOFF")
+ f.search("AFTERCUTOFF")
+
+ # pretend F
+ f.state.add_flow_setting(
+ f.flow,
+ (f.state.view_flow_mode, "fullcontents"),
+ True
+ )
+ f.master.refresh_flow(f.flow)
+
+ # text changed, now this string will exist. can happen when user presses F
+ # for full text view
+ f.search("AFTERCUTOFF")
+