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.
This commit is contained in:
Sebastián Monía 2025-04-28 08:19:06 +02:00 committed by Michael Albinus
parent c0491a8b80
commit bc5afe421b
2 changed files with 9 additions and 2 deletions

View file

@ -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)))

View file

@ -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)