Repository: qutebrowser/qutebrowser

Issue:
:navigate doesn't increment numbers in anchors or querys
**Version info (see `:version`)**:
qutebrowser v1.5.1
Git commit: c7a21b37e (2018-10-10 08:23:17 +0200)
Backend: QtWebEngine (Chromium 65.0.3325.230)

CPython: 3.7.0
Qt: 5.11.2
PyQt: 5.11.3

sip: 4.19.13
colorama: 0.3.9
pypeg2: 2.15
jinja2: 2.10
pygments: 2.2.0
yaml: 3.13
cssutils: 1.0.2 $Id$
attr: 18.2.0
PyQt5.QtWebEngineWidgets: yes
PyQt5.QtWebKitWidgets: no
pdf.js: 1.10.100 (bundled)
sqlite: 3.24.0
QtNetwork SSL: OpenSSL 1.0.2k  26 Jan 2017

Style: QWindowsVistaStyle
Platform: Windows-10-10.0.17134-SP0, 64bit
Frozen: True
Imported from C:\Program Files\qutebrowser\qutebrowser
Using Python from C:\Program Files\qutebrowser\qutebrowser.exe
Qt library executable path: C:/Program Files/qutebrowser/PyQt5/Qt/bin, data path: C:/Program Files/qutebrowser/PyQt5/Qt
OS Version: 10, 10.0.17134, SP0, Multiprocessor Free

**Does the bug happen if you start with `--temp-basedir`?** (if applicable):
Yes

**Description**
`:navigate increment` appears to only affect numbers in the path, not in the query or anchor.

**How to reproduce**
<!-- Link to the affected site, or steps to reproduce the issue
(if possible/applicable). -->
Ensure "query" is in `url.incdec_segments`.
Navigate to `http://0.0.0.0/?number=2`
Run `:navigate increment`
It complains that there is no number in the URL, but the query clearly contains a number.


Discussion:

I can reproduce this, I'm not sure why the tests in
https://github.com/qutebrowser/qutebrowser/pull/985 didn't see this.

marc-groundctl writes:

> **Version info (see `:version`)**:
> qutebrowser v1.5.1
> Git commit: c7a21b37e (2018-10-10 08:23:17 +0200)
> Backend: QtWebEngine (Chromium 65.0.3325.230)
>
> CPython: 3.7.0
> Qt: 5.11.2
> PyQt: 5.11.3
>
> sip: 4.19.13
> colorama: 0.3.9
> pypeg2: 2.15
> jinja2: 2.10
> pygments: 2.2.0
> yaml: 3.13
> cssutils: 1.0.2 $Id$
> attr: 18.2.0
> PyQt5.QtWebEngineWidgets: yes
> PyQt5.QtWebKitWidgets: no
> pdf.js: 1.10.100 (bundled)
> sqlite: 3.24.0
> QtNetwork SSL: OpenSSL 1.0.2k  26 Jan 2017
>
> Style: QWindowsVistaStyle
> Platform: Windows-10-10.0.17134-SP0, 64bit
> Frozen: True
> Imported from C:\Program Files\qutebrowser\qutebrowser
> Using Python from C:\Program Files\qutebrowser\qutebrowser.exe
> Qt library executable path: C:/Program Files/qutebrowser/PyQt5/Qt/bin, data path: C:/Program Files/qutebrowser/PyQt5/Qt
> OS Version: 10, 10.0.17134, SP0, Multiprocessor Free
>
> **Does the bug happen if you start with `--temp-basedir`?** (if applicable):
> Yes
>
> **Description**
> `:navigate increment` appears to only affect numbers in the path, not in the query or anchor.
>
> **How to reproduce**
> <!-- Link to the affected site, or steps to reproduce the issue
> (if possible/applicable). -->
> Ensure "query" is in `url.incdec_segments`.
> Navigate to `http://0.0.0.0/?number=2`
> Run `:navigate increment`
> It complains that there is no number in the URL, but the query clearly contains a number.

This probably broke with #4282 (fix for #4280), though the `RemoveFragment` there is probably also incorrect in the first place. cc @lyeoh 
Yes I didn't realise #850 had already been resolved. I'll move the fragment-stripping line.

Resolving patch:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -636,7 +636,6 @@ def navigate(self, where: str, tab=False, bg=False, window=False, count=1):
         cmdutils.check_exclusive((tab, bg, window), 'tbw')
         widget = self._current_widget()
         url = self._current_url()
-        url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
 
         handlers = {
             'prev': functools.partial(navigate.prevnext, prev=True),
@@ -654,6 +653,8 @@ def navigate(self, where: str, tab=False, bg=False, window=False, count=1):
                 handler(browsertab=widget, win_id=self._win_id, baseurl=url,
                         tab=tab, background=bg, window=window)
             elif where in ['up', 'increment', 'decrement']:
+                if where == 'up':
+                    url = url.adjusted(QUrl.RemoveFragment | QUrl.RemoveQuery)
                 new_url = handlers[where](url, count)
                 self._open(new_url, tab, bg, window, related=True)
             else:  # pragma: no cover


Test patch:
diff --git a/tests/end2end/features/navigate.feature b/tests/end2end/features/navigate.feature
--- a/tests/end2end/features/navigate.feature
+++ b/tests/end2end/features/navigate.feature
@@ -125,6 +125,12 @@ Feature: Using :navigate
         And I run :navigate increment
         Then the error "No number found in URL!" should be shown
 
+    Scenario: Incrementing query
+        When I set url.incdec_segments to ["query"]
+        And I open data/numbers/1.txt?value=2
+        And I run :navigate increment
+        Then data/numbers/1.txt?value=3 should be loaded
+
     @qtwebengine_todo: Doesn't find any elements
     Scenario: Navigating multiline links
         When I open data/navigate/multilinelinks.html