Repository: qutebrowser/qutebrowser

Issue:
Links go to about blank on qute://help
When opening `qute://help` without a trailing slash and clicking a link, it points to `about:blank`.


Discussion:
I suspected this has something do with path being an empty string. Is this a valid fix?

```diff
diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py
index b49520002..48a0ea31f 100644
--- a/qutebrowser/browser/qutescheme.py
+++ b/qutebrowser/browser/qutescheme.py
@@ -140,10 +140,13 @@ def data_for_url(url):
     # A url like "qute:foo" is split as "scheme:path", not "scheme:host".
     log.misc.debug("url: {}, path: {}, host {}".format(
         url.toDisplayString(), path, host))
-    if path and not host:
+    if not path or not host:
         new_url = QUrl()
         new_url.setScheme('qute')
-        new_url.setHost(path)
+        if host:
+            new_url.setHost(host)
+        else:
+            new_url.setHost(path)
         new_url.setPath('/')
         if new_url.host():  # path was a valid host
             raise Redirect(new_url)

```

@deewakar That looks good! Though I think it'd be good to add some comments in the `if host:` block, something like `# e.g. qute://help (without trailing slash)` and `# e.g. qute:help`.

Do you want to open a PR with this?
@The-Compiler Ok, will add those comments. Thought I'll show you before opening a PR, should I go ahead then?
Yeah, please do! 😄 

Resolving patch:
diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py
--- a/qutebrowser/browser/qutescheme.py
+++ b/qutebrowser/browser/qutescheme.py
@@ -138,14 +138,23 @@ def data_for_url(url):
     """
     path = url.path()
     host = url.host()
+    query = url.query()
     # A url like "qute:foo" is split as "scheme:path", not "scheme:host".
     log.misc.debug("url: {}, path: {}, host {}".format(
         url.toDisplayString(), path, host))
-    if path and not host:
+    if not path or not host:
         new_url = QUrl()
         new_url.setScheme('qute')
-        new_url.setHost(path)
+        # When path is absent, e.g. qute://help (with no trailing slash)
+        if host:
+            new_url.setHost(host)
+        # When host is absent, e.g. qute:help
+        else:
+            new_url.setHost(path)
+
         new_url.setPath('/')
+        if query:
+            new_url.setQuery(query)
         if new_url.host():  # path was a valid host
             raise Redirect(new_url)
 


Test patch:
diff --git a/tests/end2end/features/qutescheme.feature b/tests/end2end/features/qutescheme.feature
--- a/tests/end2end/features/qutescheme.feature
+++ b/tests/end2end/features/qutescheme.feature
@@ -55,6 +55,14 @@ Feature: Special qute:// pages
         And I hint with args "links normal" and follow a
         Then qute://help/quickstart.html should be loaded
 
+    Scenario: Opening a link with qute://help
+        When the documentation is up to date
+        And I run :tab-only
+        And I open qute://help without waiting
+        And I wait until qute://help/ is loaded
+        And I hint with args "links normal" and follow a
+        Then qute://help/quickstart.html should be loaded
+
     # :history
 
     Scenario: :history without arguments
@@ -139,12 +147,12 @@ Feature: Special qute:// pages
 
     Scenario: Running :pyeval
         When I run :debug-pyeval 1+1
-        And I wait until qute://pyeval is loaded
+        And I wait until qute://pyeval/ is loaded
         Then the page should contain the plaintext "2"
 
     Scenario: Causing exception in :pyeval
         When I run :debug-pyeval 1/0
-        And I wait until qute://pyeval is loaded
+        And I wait until qute://pyeval/ is loaded
         Then the page should contain the plaintext "ZeroDivisionError"
 
     Scenario: Running :pyeval with --quiet
@@ -158,7 +166,7 @@ Feature: Special qute:// pages
         And I run :message-warning the-warning-message
         And I run :message-info the-info-message
         And I run :messages
-        Then qute://log?level=info should be loaded
+        Then qute://log/?level=info should be loaded
         And the error "the-error-message" should be shown
         And the warning "the-warning-message" should be shown
         And the page should contain the plaintext "the-error-message"
@@ -170,7 +178,7 @@ Feature: Special qute:// pages
         And I run :message-warning the-warning-message
         And I run :message-info the-info-message
         And I run :messages warning
-        Then qute://log?level=warning should be loaded
+        Then qute://log/?level=warning should be loaded
         And the error "the-error-message" should be shown
         And the warning "the-warning-message" should be shown
         And the page should contain the plaintext "the-error-message"
@@ -182,7 +190,7 @@ Feature: Special qute:// pages
         And I run :message-warning the-warning-message
         And I run :message-info the-info-message
         And I run :messages info
-        Then qute://log?level=info should be loaded
+        Then qute://log/?level=info should be loaded
         And the error "the-error-message" should be shown
         And the warning "the-warning-message" should be shown
         And the page should contain the plaintext "the-error-message"