Handle multiple directory separators in gnus-search results
authorEric Abrahamsen <eric@ericabrahamsen.net>
Fri, 18 Feb 2022 16:37:33 +0000 (08:37 -0800)
committerEric Abrahamsen <eric@ericabrahamsen.net>
Fri, 18 Feb 2022 16:37:33 +0000 (08:37 -0800)
Try to treat the file names more like file names, less like strings
to massage.

* lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output): Use
`expand-file-name' to collapse separators and generally canonicalize
the name. Use `file-name-split' and joining instead of regexp
munging.

lisp/gnus/gnus-search.el

index 27b07e36556f562a1c63e97b45457789ed568f65..4ca873eeec91b49a03862bc12d45f69d2b78558a 100644 (file)
@@ -1393,18 +1393,27 @@ Returns a list of [group article score] vectors."
        (when (and f-name
                    (file-readable-p f-name)
                   (null (file-directory-p f-name)))
-          (setq group
-                (replace-regexp-in-string
-                "[/\\]" "."
-                (replace-regexp-in-string
-                 "/?\\(cur\\|new\\|tmp\\)?/\\'" ""
+          ;; `expand-file-name' canoncalizes the file name,
+          ;; specifically collapsing multiple consecutive directory
+          ;; separators.
+          (setq f-name (expand-file-name f-name)
+                group
+                (delete
+                 "" ; forward slash at root leaves an empty string
+                 (file-name-split
                  (replace-regexp-in-string
-                  "\\`\\." ""
-                  (string-remove-prefix
+                  "\\`\\." "" ; why do we do this?
+                   (string-remove-prefix
                     prefix (file-name-directory f-name))
-                   nil t)
-                 nil t)
-                nil t))
+                   nil t)))
+                ;; Turn file name segments into a Gnus group name.
+                group (mapconcat
+                       #'identity
+                       (if (member (car (last group))
+                                   '("new" "tmp" "cur"))
+                           (nbutlast group)
+                         group)
+                       "."))
           (setq article (file-name-nondirectory f-name)
                 article
                 ;; TODO: Provide a cleaner way of producing final