Kaynağa Gözat

Fix file:// uri handling for windows-nt and cygwin

* lisp/org-element.el (org-element-link-parser):
  Handle drive names in uri like file:///c:/dir/file

* lisp/ox.el (org-export-file-uri):
  Handle drive names in uri like file:///c:/dir/file

* testing/lisp/test-ox.el (test-org-export/file-uri):
  Generate the right uri to be tested against link exporter.
Fabrice Popineau 8 yıl önce
ebeveyn
işleme
b5a67ebddd
3 değiştirilmiş dosya ile 8 ekleme ve 6 silme
  1. 1 1
      lisp/org-element.el
  2. 5 3
      lisp/ox.el
  3. 2 2
      testing/lisp/test-ox.el

+ 1 - 1
lisp/org-element.el

@@ -3195,7 +3195,7 @@ Assume point is at the beginning of the link."
 	(when (string-match "::\\(.*\\)\\'" path)
 	  (setq search-option (match-string 1 path))
 	  (setq path (replace-match "" nil nil path)))
-	(setq path (replace-regexp-in-string "\\`///+" "/" path)))
+	(setq path (replace-regexp-in-string "\\`///*\\(.:\\)?/" "\\1/" path)))
       ;; Translate link, if `org-link-translation-function' is set.
       (let ((trans (and (functionp org-link-translation-function)
 			(funcall org-link-translation-function type path))))

+ 5 - 3
lisp/ox.el

@@ -4323,11 +4323,13 @@ has type \"radio\"."
 
 (defun org-export-file-uri (filename)
   "Return file URI associated to FILENAME."
-  (cond ((string-match-p "\\`//" filename) (concat "file:" filename))
+  (cond ((string-prefix-p "//" filename) (concat "file:" filename))
 	((not (file-name-absolute-p filename)) filename)
 	((org-file-remote-p filename) (concat "file:/" filename))
-	(t (concat "file://" (expand-file-name filename)))))
-
+	(t
+	 (let ((fullname (expand-file-name filename)))
+	   (concat (if (string-prefix-p "/" fullname) "file://" "file:///")
+		   fullname)))))
 
 ;;;; For References
 ;;

+ 2 - 2
testing/lisp/test-ox.el

@@ -3233,7 +3233,7 @@ Another text. (ref:text)
   ;; Preserve relative filenames.
   (should (equal "relative.org" (org-export-file-uri "relative.org")))
   ;; Local files start with "file://"
-  (should (equal (concat "file://" (expand-file-name "/local.org"))
+  (should (equal (concat (if (memq system-type '(windows-nt cygwin)) "file:///" "file://") (expand-file-name "/local.org"))
 		 (org-export-file-uri "/local.org")))
   ;; Remote files start with "file://"
   (should (equal "file://myself@some.where:papers/last.pdf"
@@ -3242,7 +3242,7 @@ Another text. (ref:text)
 		 (org-export-file-uri "//localhost/etc/fstab")))
   ;; Expand filename starting with "~".
   (should (equal (org-export-file-uri "~/file.org")
-		 (concat "file://" (expand-file-name "~/file.org")))))
+		 (concat (if (memq system-type '(windows-nt cygwin)) "file:///" "file://") (expand-file-name "~/file.org")))))
 
 (ert-deftest test-org-export/get-reference ()
   "Test `org-export-get-reference' specifications."