From: Eli Zaretskii Date: Fri, 8 Sep 2017 07:51:14 +0000 (+0300) Subject: Fix 'directory-file-name' on DOS_NT systems as well X-Git-Tag: emacs-26.0.90~233 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e2a10d7fa8092ef51a3b61a363061e37224e2ca1;p=emacs.git Fix 'directory-file-name' on DOS_NT systems as well * src/fileio.c (directory_file_name) [DOS_NT]: Fix the DOS_NT case to be consistent with last change. * test/src/fileio-tests.el (fileio-tests--odd-symlink-chars): Disable on MS-Windows. (fileio-tests--directory-file-name-dos-nt) (fileio-tests--file-name-as-directory-dos-nt): New tests. --- diff --git a/src/fileio.c b/src/fileio.c index 9df3b1bedae..a1cea94c0b6 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -572,7 +572,7 @@ directory_file_name (char *dst, char *src, ptrdiff_t srclen, bool multibyte) if (! (srclen == 2 && IS_DIRECTORY_SEP (src[0]))) while (srclen > 1 #ifdef DOS_NT - && !IS_ANY_SEP (src[srclen - 2]) + && !(srclen > 2 && IS_DEVICE_SEP (src[srclen - 2])) #endif && IS_DIRECTORY_SEP (src[srclen - 1])) srclen--; diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index ac5d533e63b..7ac70a58961 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -43,6 +43,10 @@ (ert-deftest fileio-tests--odd-symlink-chars () "Check that any non-NULL ASCII character can appear in a symlink. Also check that an encoding error can appear in a symlink." + ;; Some Windows versions don't support symlinks, and those which do + ;; will pop up UAC elevation prompts, so we disable this test on + ;; MS-Windows. + (skip-unless (not (eq system-type 'windows-nt))) (should (equal nil (fileio-tests--symlink-failure)))) (ert-deftest fileio-tests--directory-file-name () @@ -54,6 +58,17 @@ Also check that an encoding error can appear in a symlink." (should (equal (directory-file-name "/abc/") "/abc")) (should (equal (directory-file-name "/abc//") "/abc"))) +(ert-deftest fileio-tests--directory-file-name-dos-nt () + "Like fileio-tests--directory-file-name, but for DOS_NT systems." + (skip-unless (memq system-type '(ms-dos windows-nt))) + (should (equal (directory-file-name "d:/") "d:/")) + (should (equal (directory-file-name "d://") "d:/")) + (should (equal (directory-file-name "d:///") "d:/")) + (should (equal (directory-file-name "d:////") "d:/")) + (should (equal (directory-file-name "d:/abc") "d:/abc")) + (should (equal (directory-file-name "d:/abc/") "d:/abc")) + (should (equal (directory-file-name "d:/abc//") "d:/abc"))) + (ert-deftest fileio-tests--file-name-as-directory () (should (equal (file-name-as-directory "") "./")) (should (equal (file-name-as-directory "/") "/")) @@ -63,3 +78,18 @@ Also check that an encoding error can appear in a symlink." (should (equal (file-name-as-directory "/abc") "/abc/")) (should (equal (file-name-as-directory "/abc/") "/abc/")) (should (equal (file-name-as-directory "/abc//") "/abc//"))) + +(ert-deftest fileio-tests--file-name-as-directory-dos-nt () + "Like fileio-tests--file-name-as-directory, but for DOS_NT systems." + (skip-unless (memq system-type '(ms-dos windows-nt))) + (should (equal (file-name-as-directory "d:/") "d:/")) + (should (equal (file-name-as-directory "d:\\") "d:/")) + (should (equal (file-name-as-directory "d://") "d://")) + (should (equal (file-name-as-directory "d:///") "d:///")) + (should (equal (file-name-as-directory "d:////") "d:////")) + (should (equal (file-name-as-directory "d:\\\\\\\\") "d:////")) + (should (equal (file-name-as-directory "d:/abc") "d:/abc/")) + (should (equal (file-name-as-directory "D:\\abc") "d:/abc/")) + (should (equal (file-name-as-directory "d:/abc/") "d:/abc/")) + (should (equal (file-name-as-directory "D:\\abc/") "d:/abc/")) + (should (equal (file-name-as-directory "D:/abc//") "d:/abc//")))