From b42463a49eca1f319bc1830f70295e8f127fb40b Mon Sep 17 00:00:00 2001 From: plugd Date: Fri, 15 Jul 2022 16:12:23 +1000 Subject: [PATCH] Fixed an issue with parsing scheme://@host urls. --- elpher.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/elpher.el b/elpher.el index 398aac2..1573581 100644 --- a/elpher.el +++ b/elpher.el @@ -447,17 +447,21 @@ For gopher addresses this is a combination of the selector type and selector." (defun elpher-address-host (address) "Retrieve host from ADDRESS object." - (let ((host-pre (url-host address))) + (pcase (url-host address) ;; The following strips out square brackets which sometimes enclose IPv6 ;; addresses. Doing this here rather than at the parsing stage may seem ;; weird, but this lets us way we avoid having to muck with both URL parsing ;; and reconstruction. It's also more efficient, as this method is not ;; called during page rendering. - (if (and (> (length host-pre) 2) - (eq (elt host-pre 0) ?\[) - (eq (elt host-pre (- (length host-pre) 1)) ?\])) - (substring host-pre 1 (- (length host-pre) 1)) - host-pre))) + ((rx (: "[" (let ipv6 (* (not "]"))) "]")) + ipv6) + ;; The following is a work-around for a parsing bug that causes + ;; URLs with empty (but not absent, see RFC 1738) usernames to have + ;; @ prepended to the hostname. + ((rx (: "@" (let rest (+ anything)))) + rest) + (addr + addr))) (defun elpher-address-user (address) "Retrieve user from ADDRESS object." -- 2.20.1