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.
This commit is contained in:
Florian Bruhin 2016-04-25 18:53:35 +02:00
parent a5679dff04
commit 6349c00c72
3 changed files with 29 additions and 0 deletions

View File

@ -36,6 +36,13 @@ Changed
the right.
- `:yank` can now yank the pretty/decoded URL by adding `--pretty`
Fixed
~~~~~
- Fixed crash when using `:tab-{prev,next,focus}` right after closing the last
tab with `last-close` set to `close`.
v0.6.1
-----

View File

@ -785,6 +785,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)
@ -801,6 +805,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)

View File

@ -851,3 +851,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