diff --git a/bebop/browser.py b/bebop/browser.py index e71cddf..3a81e5e 100644 --- a/bebop/browser.py +++ b/bebop/browser.py @@ -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.""" diff --git a/bebop/tests/test_navigation.py b/bebop/tests/test_navigation.py index e32207a..83a9592 100644 --- a/bebop/tests/test_navigation.py +++ b/bebop/tests/test_navigation.py @@ -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")