Browse Source

Fix file uri

* lisp/ox.el (org-export-file-uri): Properly expand file uri.

* lisp/org-element.el (org-element-link-parser): Start path with "//"
  when referring to a remote file.

* testing/lisp/test-ox.el (test-org-export/file-uri): Add test.

Reported-by: AW <alexander.willand@t-online.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/101471>
Nicolas Goaziou 5 years ago
parent
commit
fd8a18151a
3 changed files with 8 additions and 8 deletions
  1. 2 2
      lisp/org-element.el
  2. 4 6
      lisp/ox.el
  3. 2 0
      testing/lisp/test-ox.el

+ 2 - 2
lisp/org-element.el

@@ -3125,13 +3125,13 @@ 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 "\\`///+" "/" 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))))
 	(when trans
 	  (setq type (car trans))
-	 (setq path (cdr trans))))
+	  (setq path (cdr trans))))
       (list 'link
 	    (list :type type
 		  :path path

+ 4 - 6
lisp/ox.el

@@ -4199,12 +4199,10 @@ has type \"radio\"."
 
 (defun org-export-file-uri (filename)
   "Return file URI associated to FILENAME."
-  (if (not (file-name-absolute-p filename)) filename
-    (concat "file:/"
-	    (and (not (org-file-remote-p filename)) "/")
-	    (if (org-string-match-p "\\`~" filename)
-		(expand-file-name filename)
-	      filename))))
+  (cond ((org-string-match-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)))))
 
 
 ;;;; For References

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

@@ -2728,6 +2728,8 @@ Another text. (ref:text)
   ;; Remote files start with "file://"
   (should (equal "file://myself@some.where:papers/last.pdf"
 		 (org-export-file-uri "/myself@some.where:papers/last.pdf")))
+  (should (equal "file://localhost/etc/fstab"
+		 (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")))))