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.
This commit is contained in:
Fabrice Popineau 2017-02-16 22:42:59 +01:00 committed by Nicolas Goaziou
parent b897ab7223
commit b5a67ebddd
3 changed files with 8 additions and 6 deletions

View File

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

View File

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

View File

@ -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."