browser: fix relative link issue
This commit is contained in:
parent
657d46adc5
commit
294c7796fa
|
@ -162,11 +162,13 @@ class Browser:
|
|||
return
|
||||
if assume_absolute or not self.current_url:
|
||||
parts = parse_url(url, absolute=True)
|
||||
join = False
|
||||
else:
|
||||
parts = parse_url(url)
|
||||
join = True
|
||||
if parts.scheme == "gemini":
|
||||
# If there is no netloc, this is a relative URL.
|
||||
if not parts.netloc:
|
||||
if join:
|
||||
url = join_url(self.current_url, url)
|
||||
self.open_gemini_url(sanitize_url(url), redirections)
|
||||
else:
|
||||
|
@ -315,9 +317,11 @@ class Browser:
|
|||
validator = lambda ch: self._validate_link_digit(ch, links, max_digits)
|
||||
link_input = self.command_line.focus("&", validator, digit)
|
||||
try:
|
||||
self.open_link(links, int(link_input))
|
||||
except ValueError:
|
||||
self.set_status_error("Invalid link ID.")
|
||||
link_id = int(link_input)
|
||||
except ValueError as exc:
|
||||
self.set_status_error(f"Invalid link ID {link_input}.")
|
||||
return
|
||||
self.open_link(links, link_id)
|
||||
|
||||
def _validate_link_digit(self, ch: int, links, max_digits: int):
|
||||
"""Handle input chars to be used as link ID."""
|
||||
|
|
|
@ -19,10 +19,17 @@ class TestNavigation(unittest.TestCase):
|
|||
self.assertEqual(res.netloc, "dece.space")
|
||||
self.assertEqual(res.path, "/parse-me.gmi")
|
||||
|
||||
res = parse_url("https://dece.space/index.html")
|
||||
self.assertEqual(res.scheme, "https")
|
||||
self.assertEqual(res.netloc, "dece.space")
|
||||
self.assertEqual(res.path, "/index.html")
|
||||
|
||||
def test_join_url(self):
|
||||
url = join_url("gemini://dece.space", "some-file.gmi")
|
||||
url = join_url("gemini://dece.space/", "some-file.gmi")
|
||||
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
||||
url = join_url("gemini://dece.space", "some-file.gmi")
|
||||
url = join_url("gemini://dece.space/", "./some-file.gmi")
|
||||
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
||||
url = join_url("gemini://dece.space/dir1", "/some-file.gmi")
|
||||
self.assertEqual(url, "gemini://dece.space/some-file.gmi")
|
||||
url = join_url("gemini://dece.space/dir1/file.gmi", "other-file.gmi")
|
||||
self.assertEqual(url, "gemini://dece.space/dir1/other-file.gmi")
|
||||
|
|
Reference in a new issue