commit 9de31b2aa50f5c35b13f33eb5506d560f180844b
parent e24313a14c4ad496f418f47c1cd6162373234ef3
Author: René Wagner <rwa@clttr.info>
Date: Tue, 16 Aug 2022 19:38:41 +0200
fix normalizing of URIs with default port
It seems that urlsplit.port can not be string-compared for some reason.
So we simply always replace the port portion - i assume this is fine
for almost everything out there.
fixes #55
Diffstat:
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/gus/lib/gemini.py b/gus/lib/gemini.py
@@ -392,12 +392,11 @@ class GeminiResource:
def _get_normalized_url_and_host(self):
url_normalized = unquote(self.fetchable_url.rstrip("/"))
- if self.urlsplit.port == "1965":
- url_normalized = url_normalized.replace(
- self.urlsplit.hostname.lower() + ":1965",
- self.urlsplit.hostname.lower(),
- 1,
- )
+ url_normalized = url_normalized.replace(
+ self.urlsplit.hostname.lower() + ":1965",
+ self.urlsplit.hostname.lower(),
+ 1,
+ )
host_normalized = self.urlsplit.hostname.lower()
return url_normalized, host_normalized
diff --git a/tests/gus/lib/test_gemini.py b/tests/gus/lib/test_gemini.py
@@ -51,8 +51,9 @@ text
(["/bar", "gemini://gus.guru/foo/", "gus.guru"], [True, "gemini://gus.guru/bar", "gus.guru"]),
(["bar", "gemini://gus.guru/foo", "gus.guru"], [True, "gemini://gus.guru/bar", "gus.guru"]),
(["bar", "gemini://gus.guru/foo/", "gus.guru"], [True, "gemini://gus.guru/foo/bar", "gus.guru"]),
- # (["bar", "gemini://gus.guru/foo", "gus.guru"], [True, "gemini://gus.guru/foo/bar", "gus.guru"]),
(["//foo.com", None, None], [True, "gemini://foo.com", "foo.com"]),
+ (["gemini://gem.splatt9990.com/index.gmi", None, None], [True, "gemini://gem.splatt9990.com/index.gmi", "gem.splatt9990.com"]),
+ (["gemini://gem.splatt9990.com:1965/index.gmi", None, None], [True, "gemini://gem.splatt9990.com/index.gmi", "gem.splatt9990.com"]),
])
def test_url_parsing(self, test_input, expected_result):
@@ -134,12 +135,10 @@ Allow: /""")
Disallow: /cgi-bin/wp.cgi/view
Disallow: /cgi-bin/wp.cgi/media
Disallow: /cgi-bin/wp.cgi/search
-
Disallow: /cgi-bin/waffle.cgi/article
Disallow: /cgi-bin/waffle.cgi/feed
Disallow: /cgi-bin/waffle.cgi/links
Disallow: /cgi-bin/waffle.cgi/view
-
Disallow: /cgi-bin/witw.cgi/play
""")
self._assert_fetchable(rp, "/cgi-bin/waffle.cgi/feed/link", False)