From b5a67ebddd0afe24126fedcd10017d92502c6f10 Mon Sep 17 00:00:00 2001 From: Fabrice Popineau Date: Thu, 16 Feb 2017 22:42:59 +0100 Subject: [PATCH] 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. --- lisp/org-element.el | 2 +- lisp/ox.el | 8 +++++--- testing/lisp/test-ox.el | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 192062561..f12061995 100644 --- a/lisp/org-element.el +++ b/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)))) diff --git a/lisp/ox.el b/lisp/ox.el index 82230b6bf..55ad101c1 100644 --- a/lisp/ox.el +++ b/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 ;; diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index cfcf05e08..3d68f224b 100644 --- a/testing/lisp/test-ox.el +++ b/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." -- 2.11.4.GIT