From: Sebastián Monía Date: Mon, 28 Apr 2025 06:19:06 +0000 (+0200) Subject: url-parse.el: correct code for Windows paths (bug#76982) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9a13afb174e32c565b3bd673338f09e5831c3991;p=emacs.git url-parse.el: correct code for Windows paths (bug#76982) * lisp/url/url-parse.el (url-recreate-url): Handle empty filenames without errors. * test/lisp/url/url-parse-tests.el (url-generic-parse-url/ms-windows-file-uri-hanlding): Add one more test for the scenario above. (cherry picked from commit bc5afe421b47ec31ce94ad8dc02912acd93c3319) --- diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el index d2f49ef2c5f..195cc957668 100644 --- a/lisp/url/url-parse.el +++ b/lisp/url/url-parse.el @@ -86,6 +86,7 @@ If the specified port number is the default, return nil." ;; For Windows/DOS-like paths, `url-generic-parse-url' strips ;; the leading /, so we need to add it back (bug#76982) (file (if (and (string= "file" type) + (url-filename urlobj) (string-match "^[A-Za-z]:[/\\]" (url-filename urlobj))) (concat "/" (url-filename urlobj)) (url-filename urlobj))) diff --git a/test/lisp/url/url-parse-tests.el b/test/lisp/url/url-parse-tests.el index c4c4b2fc8f8..66b27f3a638 100644 --- a/test/lisp/url/url-parse-tests.el +++ b/test/lisp/url/url-parse-tests.el @@ -190,10 +190,16 @@ (should (equal (url-filename (url-generic-parse-url "file:///c:\\directory\\file.txt")) "c:\\directory\\file.txt")) - ;; + ;; paths with hostname = "localhost" should work too (should (equal (url-filename (url-generic-parse-url "file://localhost/c:/path/to/file")) - "c:/path/to/file"))) + "c:/path/to/file")) + ;; empty "file" url structs have to behave as they did before this fix + (should (equal (url-recreate-url + (url-parse-make-urlobj "file" nil nil "myhost" nil + nil nil nil t)) + "file://myhost/"))) + (provide 'url-parse-tests)