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