navigation: fix issue with reloading bebop pages
This commit is contained in:
parent
09f660feaf
commit
2b684d7afc
|
@ -27,7 +27,6 @@ BACKLOG
|
|||
--------------------------------------------------------------------------------
|
||||
bug: can't input unicode
|
||||
click on links to open them
|
||||
bug: can't reload bebop: pages
|
||||
bug: exiting editor breaks curses
|
||||
dumb rendering mode per site
|
||||
well, preferences per site maybe?
|
||||
|
|
|
@ -12,7 +12,9 @@ from pathlib import Path
|
|||
from typing import Dict, Optional, Tuple
|
||||
|
||||
from bebop.bookmarks import (
|
||||
get_bookmarks_path, get_bookmarks_document, save_bookmark
|
||||
get_bookmarks_path,
|
||||
get_bookmarks_document,
|
||||
save_bookmark,
|
||||
)
|
||||
from bebop.colors import ColorPair, init_colors
|
||||
from bebop.command_line import CommandLine
|
||||
|
@ -25,7 +27,12 @@ from bebop.links import Links
|
|||
from bebop.mime import MimeType
|
||||
from bebop.mouse import ButtonState
|
||||
from bebop.navigation import (
|
||||
get_parent_url, get_root_url, join_url, parse_url, unparse_url
|
||||
NO_NETLOC_SCHEMES,
|
||||
get_parent_url,
|
||||
get_root_url,
|
||||
join_url,
|
||||
parse_url,
|
||||
unparse_url,
|
||||
)
|
||||
from bebop.page import Page
|
||||
from bebop.page_pad import PagePad
|
||||
|
@ -346,7 +353,11 @@ class Browser:
|
|||
parts = parse_url(url, default_scheme=current_scheme)
|
||||
|
||||
# If there is a no netloc part, try to join the URL.
|
||||
if parts["netloc"] is None and parts["scheme"] == current_scheme:
|
||||
if (
|
||||
parts["netloc"] is None
|
||||
and parts["scheme"] == current_scheme
|
||||
and parts["scheme"] not in NO_NETLOC_SCHEMES
|
||||
):
|
||||
base_url = base_url or self.current_url
|
||||
if base_url:
|
||||
parts = parse_url(join_url(base_url, url))
|
||||
|
|
|
@ -20,6 +20,8 @@ URI_RE = re.compile(
|
|||
"$"
|
||||
)
|
||||
|
||||
NO_NETLOC_SCHEMES = ("bebop",)
|
||||
|
||||
|
||||
class InvalidUrlException(Exception):
|
||||
"""Generic exception for invalid URLs used in this module."""
|
||||
|
@ -45,7 +47,8 @@ def parse_url(
|
|||
- absolute: assume the URL is absolute, e.g. in the case we are trying to
|
||||
parse an URL an user has written, which is most of the time an absolute
|
||||
URL even if not perfectly so. This only has an effect if, after the
|
||||
initial parsing, there is no netloc available.
|
||||
initial parsing, there is no netloc available and if there is no scheme
|
||||
that is known to not have a netloc (i.e. the dummy "bebop" scheme).
|
||||
- default_scheme: specify the scheme to use if the URL either does not
|
||||
specify it and we need it (e.g. there is a location), or `absolute` is
|
||||
true; if absolute is true but `default_scheme` is not specified, a netloc
|
||||
|
@ -71,7 +74,11 @@ def parse_url(
|
|||
|
||||
# Smol hack: if we assume it's an absolute URL and no netloc has been found,
|
||||
# just prefix default scheme (if any) and "//".
|
||||
if absolute and not parts["netloc"]:
|
||||
if (
|
||||
absolute
|
||||
and not parts["netloc"]
|
||||
and parts["scheme"] not in NO_NETLOC_SCHEMES
|
||||
):
|
||||
scheme = parts["scheme"] or default_scheme
|
||||
prefix = scheme + "://" if scheme else "//"
|
||||
return parse_url(prefix + url)
|
||||
|
|
|
@ -50,6 +50,12 @@ class TestNavigation(unittest.TestCase):
|
|||
self.assertEqual(res["scheme"], "file")
|
||||
self.assertEqual(res["path"], "/home/dece/gemini/index.gmi")
|
||||
|
||||
# Bebop scheme.
|
||||
res = parse_url("bebop:welcome")
|
||||
self.assertEqual(res["scheme"], "bebop")
|
||||
self.assertIsNone(res["netloc"])
|
||||
self.assertEqual(res["path"], "welcome")
|
||||
|
||||
def test_join_url(self):
|
||||
url = join_url("gemini://dece.space/", "some-file.gmi")
|
||||
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
||||
|
|
Reference in a new issue