X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=bd9cbb56cbf1f304b1fba56a5f4a5f962e8a6e19;hp=2e3c5ec7468531356c74c75be812c69abdfbb49f;hb=88f19dc9704f8e44316715b31c12154be7c1deaa;hpb=7b52709ddf798fe53db3855eef52ca8862e7700d diff --git a/elpher.el b/elpher.el index 2e3c5ec..bd9cbb5 100644 --- a/elpher.el +++ b/elpher.el @@ -1429,17 +1429,22 @@ Returns the url portion in the event that the display-string portion is empty." rest)))) (defun elpher-collapse-dot-sequences (filename) - "Collapse dot sequences in FILENAME. -For instance, the filename /a/b/../c/./d will reduce to /a/c/d" - (let* ((path (split-string filename "/")) + "Collapse dot sequences in the (absolute) FILENAME. +For instance, the filename \"/a/b/../c/./d\" will reduce to \"/a/c/d\"" + (let* ((path (split-string filename "/" t)) (path-reversed-normalized (seq-reduce (lambda (a b) - (cond ((and a (equal b "..") (cdr a))) - ((and (not a) (equal b "..")) a) ;leading .. are dropped + (cond ((equal b "..") (cdr a)) ((equal b ".") a) (t (cons b a)))) - path nil))) - (string-join (reverse path-reversed-normalized) "/"))) + path nil)) + (path-normalized (reverse path-reversed-normalized))) + (if path-normalized + (concat + "/" + (string-join (reverse path-reversed-normalized) "/") + (if (string-match-p (rx (: (or "." ".." "/") line-end)) filename) "/") "") + "/"))) (defun elpher-address-from-gemini-url (url) "Extract address from URL with defaults as per gemini map files.