emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7eca680e54 1/2: Make file-name-split returns driver name as well


From: Lars Ingebrigtsen
Subject: master 7eca680e54 1/2: Make file-name-split returns driver name as well in Windows
Date: Wed, 6 Apr 2022 06:24:53 -0400 (EDT)

branch: master
commit 7eca680e5441a8c2315f3b39e5e1d5581661316c
Author: Kien Nguyen <kien.n.quang@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make file-name-split returns driver name as well in Windows
    
    * lisp/files.el (file-name-split): Returns driver name as well in
    Windows.
    * lisp/net/browse-url.el (browse-url-file-url): Don't hexify colon
    character in file path for Windows (bug#54721).
---
 lisp/files.el          |  6 +++++-
 lisp/net/browse-url.el | 15 ++++++++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index a0bc5bf262..2aa6c9dedc 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5091,7 +5091,11 @@ On most systems, this will be true:
         ;; If there's nothing left to peel off, we're at the root and
         ;; we can stop.
         (when (and dir (equal dir filename))
-          (push "" components)
+          (push (if (equal dir "") ""
+                  ;; On Windows, the first component might be "c:" or
+                  ;; the like.
+                  (substring dir 0 -1))
+                components)
           (setq filename nil))))
     components))
 
diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 4c348781a8..66898d7707 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -728,9 +728,18 @@ Use variable `browse-url-filename-alist' to map filenames 
to URLs."
                      browse-url-filename-alist))
       (setq file (browse-url-url-encode-chars file "[*\"()',=;?% ]"))
     ;; Encode all other file names properly.
-    (setq file (mapconcat #'url-hexify-string
-                          (file-name-split file)
-                          "/")))
+    (let ((bits (file-name-split file)))
+      (setq file
+            (string-join
+             ;; On Windows, the first bit here might be "c:" or the
+             ;; like, so don't encode the ":" in the first bit.
+             (cons (let ((url-unreserved-chars
+                          (if (file-name-absolute-p file)
+                              (cons ?: url-unreserved-chars)
+                            url-unreserved-chars)))
+                     (url-hexify-string (car bits)))
+                   (mapcar #'url-hexify-string (cdr bits)))
+             "/"))))
   (dolist (map browse-url-filename-alist)
     (when (and map (string-match (car map) file))
       (setq file (replace-match (cdr map) t nil file))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]