diff options
author | Florian Bruhin <git@the-compiler.org> | 2016-04-25 18:53:35 +0200 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2016-04-30 14:41:26 +0200 |
commit | ea2ae94cd0df715abf6db2c9dac16016a2a38d13 (patch) | |
tree | aa23c57bcad60a5f88f5be10b64f1c6385e664e1 | |
parent | 356eb7e5e7cf49c5208d921767743c1a01991bec (diff) | |
download | qutebrowser-ea2ae94cd0df715abf6db2c9dac16016a2a38d13.tar.gz qutebrowser-ea2ae94cd0df715abf6db2c9dac16016a2a38d13.zip |
Fix crash with :tab-{prev,next,focus} with 0 tabs
When using :tab-prev/:tab-next (or :tab-focus which uses :tab-next
internally) immediately after the last tab, those functions could be
called with 0 tabs open, which caused a ZeroDivisionError when trying to
do % 0.
Fixes #1448.
-rw-r--r-- | qutebrowser/browser/commands.py | 8 | ||||
-rw-r--r-- | tests/integration/features/tabs.feature | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 3cae6941c..e99aefe4b 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -774,6 +774,10 @@ class CommandDispatcher: Args: count: How many tabs to switch back. """ + if self._count() == 0: + # Running :tab-prev after last tab was closed + # See https://github.com/The-Compiler/qutebrowser/issues/1448 + return newidx = self._current_index() - count if newidx >= 0: self._set_current_index(newidx) @@ -790,6 +794,10 @@ class CommandDispatcher: Args: count: How many tabs to switch forward. """ + if self._count() == 0: + # Running :tab-next after last tab was closed + # See https://github.com/The-Compiler/qutebrowser/issues/1448 + return newidx = self._current_index() + count if newidx < self._count(): self._set_current_index(newidx) diff --git a/tests/integration/features/tabs.feature b/tests/integration/features/tabs.feature index 630fa6279..b24d56cbf 100644 --- a/tests/integration/features/tabs.feature +++ b/tests/integration/features/tabs.feature @@ -822,3 +822,17 @@ Feature: Tab management When I open data/title.html And I run :buffer "1/2/3" Then the error "No matching tab for: 1/2/3" should be shown + + Scenario: Using :tab-next after closing last tab (#1448) + When I set tabs -> last-close to close + And I run :tab-only + And I run :tab-close ;; :tab-next + Then qutebrowser should quit + And no crash should happen + + Scenario: Using :tab-prev after closing last tab (#1448) + When I set tabs -> last-close to close + And I run :tab-only + And I run :tab-close ;; :tab-prev + Then qutebrowser should quit + And no crash should happen |