From 7a3d1b021282bab24d010a7d10f62051fbffee46 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 29 Nov 2018 19:28:11 +0100 Subject: [PATCH] AbstractHistory: Check count --- qutebrowser/browser/browsertab.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 2fb247a39..ad5f42ab2 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -606,11 +606,17 @@ class AbstractHistory: def __iter__(self) -> typing.Iterable: raise NotImplementedError + def _check_count(self, count: int) -> None: + """Check whether the count is positive.""" + if count < 0: + raise WebTabError("count needs to be positive!") + def current_idx(self) -> int: raise NotImplementedError def back(self, count: int = 1) -> None: """Go back in the tab's history.""" + self._check_count(count) idx = self.current_idx() - count if idx >= 0: self._go_to_item(self._item_at(idx)) @@ -620,6 +626,7 @@ class AbstractHistory: def forward(self, count: int = 1) -> None: """Go forward in the tab's history.""" + self._check_count(count) idx = self.current_idx() + count if idx < len(self): self._go_to_item(self._item_at(idx))