From 2ad4cdd729d1e495c023168e05cbb99cc1181f45 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 23 Jul 2017 18:09:10 -0400 Subject: [PATCH] Fix web-history-max-items-crash. Fixes #2849, where pressing 'o' with web-history-max-items set and no history items would cause a crash as the query result is empty. --- qutebrowser/completion/models/histcategory.py | 4 ++++ tests/unit/completion/test_histcategory.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index 612eb0bf4..2977bfee4 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -72,6 +72,10 @@ class HistoryCategory(QSqlQueryModel): 'ORDER BY last_atime DESC LIMIT :limit)', ])).run(limit=max_items).value() + if not min_atime: + # if there are no history items, min_atime may be '' (issue #2849) + return '' + return "AND last_atime >= {}".format(min_atime) def set_pattern(self, pattern): diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index c53c86ee1..e4b06eaf6 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -126,7 +126,8 @@ def test_set_pattern(pattern, before, after, model_validator, hist): ], [ ('b', 'b', '2017-06-16'), ('c', 'c', '2017-05-16'), - ]) + ]), + (1, [], []), # issue 2849 (crash with empty history) ]) def test_sorting(max_items, before, after, model_validator, hist, config_stub): """Validate the filtering and sorting results of set_pattern."""