From e810b9831045c588543454cce81d4d9e6d13ffdc Mon Sep 17 00:00:00 2001
From: Tim Vaughan <plugd@thelambdalab.xyz>
Date: Thu, 4 Jun 2020 09:52:44 +0200
Subject: [PATCH] Strip default port numbers from URL strings.

---
 elpher.el | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/elpher.el b/elpher.el
index 7605bdf..1988656 100644
--- a/elpher.el
+++ b/elpher.el
@@ -307,9 +307,25 @@ requiring gopher-over-TLS."
 
 (defun elpher-address-to-url (address)
   "Get string representation of ADDRESS, or nil if ADDRESS is special."
-  (if (not (elpher-address-special-p address))
-      (url-encode-url (url-recreate-url address))
-    nil))
+  (if (elpher-address-special-p address)
+      nil
+    (let* ((port (url-port address))
+           (address-to-convert
+            (if (= port 0)
+                address
+              (let ((address-copy (seq-copy address))
+                    (protocol (url-type address)))
+                (if (or (and (equal protocol "gopher")
+                             (= port 70))
+                        (and (equal protocol "gemini")
+                             (= port 1965))
+                        (and (equal protocol "http")
+                             (= port 80))
+                        (and (equal protocol "finger")
+                             (= port 79)))
+                    (setf (url-port address-copy) 0))
+                address-copy))))
+      (url-encode-url (url-recreate-url address-to-convert)))))
 
 (defun elpher-address-type (address)
   "Retrieve type of ADDRESS object.
-- 
2.20.1