Bug fix in gemini path normalization code.
authorplugd <plugd@thelambdalab.xyz>
Wed, 4 Aug 2021 13:58:19 +0000 (15:58 +0200)
committerplugd <plugd@thelambdalab.xyz>
Wed, 4 Aug 2021 13:58:19 +0000 (15:58 +0200)
ISSUES.org
elpher.el

index 02c18fe..b1556a0 100644 (file)
@@ -4,8 +4,30 @@
    
 * Open Bugs
 
    
 * Open Bugs
 
-** OPEN Relative Gemini links processed improperly
+** OPEN Sanitize certificate names
+   :LOGBOOK:
+   - State "OPEN"       from              [2020-06-22 Mon 10:32]
+   :END:
+   
+Currently things will break in undefined ways if a name is specified
+that contains path separators and probably other characters that I
+haven't thought of.  This is dangerously unacceptable and needs to be
+fixed right away.
+
+** OPEN Set timer after creating network process
+
+While the current order is necessary for synchronous socks
+connections, it is unecessary for regular connections which have the
+no-wait flag set.  Furthermore, for these connections, having the
+timer fire up early means that it interferes with requests for
+user interaction that may appear during the initial connection setup.
+E.g., asking for approval of uknown TLS certificates.
+
+* Closed Bugs
+
+** CLOSED Relative Gemini links processed improperly
 :LOGBOOK:
 :LOGBOOK:
+- State "CLOSED"     from "OPEN"       [2021-08-04 Wed 15:54]
 - State "OPEN"       from              [2021-08-04 Wed 13:53]
 :END:
 
 - State "OPEN"       from              [2021-08-04 Wed 13:53]
 :END:
 
@@ -29,26 +51,6 @@ The fix will be to ensure gemini://skyjake.fi/gemlog/.. collapses to
 gemini://skyjake.fi/ rather than gemini://skyjake.fi.
 
 
 gemini://skyjake.fi/ rather than gemini://skyjake.fi.
 
 
-** OPEN Sanitize certificate names
-   :LOGBOOK:
-   - State "OPEN"       from              [2020-06-22 Mon 10:32]
-   :END:
-   
-Currently things will break in undefined ways if a name is specified
-that contains path separators and probably other characters that I
-haven't thought of.  This is dangerously unacceptable and needs to be
-fixed right away.
-
-** OPEN Set timer after creating network process
-
-While the current order is necessary for synchronous socks
-connections, it is unecessary for regular connections which have the
-no-wait flag set.  Furthermore, for these connections, having the
-timer fire up early means that it interferes with requests for
-user interaction that may appear during the initial connection setup.
-E.g., asking for approval of uknown TLS certificates.
-
-* Closed Bugs
   
 ** CLOSED Org mode faces are not present in recent emacs versions
 Even 26.1 doesn't seem to have these.  This means that, for many
   
 ** CLOSED Org mode faces are not present in recent emacs versions
 Even 26.1 doesn't seem to have these.  This means that, for many
index 2e3c5ec..bd9cbb5 100644 (file)
--- 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)
                    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)
          (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))))
                               ((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.
 
 (defun elpher-address-from-gemini-url (url)
   "Extract address from URL with defaults as per gemini map files.