summaryrefslogtreecommitdiff
path: root/test/src/fileio-tests.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-08-27 14:46:52 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-08-27 14:49:38 -0700
commit0bbc84630f12e848e19c39dce01f3d14559bf70b (patch)
tree8c2e252c0ea6ef65667f4df46c468ef2f0b50bc6 /test/src/fileio-tests.el
parent1153b238aef5a48bbecd5a58cd6a14dae9ec1d2f (diff)
downloademacs-0bbc84630f12e848e19c39dce01f3d14559bf70b.tar.gz
Fix recently-introduced expand-file-name bug
The bug was that (expand-file-name "~") returned something like "/home/eggert/" instead of "/home/eggert". Problem reported by Mattias Engdegård (Bug#26911#27). * src/fileio.c (Fexpand_file_name): When concatenating NEWDIR to NM, instead of stripping trailing slashes from NEWDIR (which can turn non-symlinks into symlinks), strip leading slashes from NM. This also simplifies the code by removing no-longer-needed DOS_NT special-casing. Also, remove an unnecessary ‘target[length] = 0;’ as that byte will be overwritten by the next memcpy anyway. * test/src/fileio-tests.el (fileio-tests--HOME-trailing-slash): New test.
Diffstat (limited to 'test/src/fileio-tests.el')
-rw-r--r--test/src/fileio-tests.el8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index 1516590795e..8b76912f5e1 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -108,6 +108,14 @@ Also check that an encoding error can appear in a symlink."
(should (equal (expand-file-name "~/bar") "x:/foo/bar")))
(setenv "HOME" old-home)))
+(ert-deftest fileio-tests--HOME-trailing-slash ()
+ "Test that expand-file-name of \"~\" respects trailing slash."
+ (let ((old-home (getenv "HOME")))
+ (dolist (home '("/a/b/c" "/a/b/c/"))
+ (setenv "HOME" home)
+ (should (equal (expand-file-name "~") (expand-file-name home))))
+ (setenv "HOME" old-home)))
+
(ert-deftest fileio-tests--expand-file-name-trailing-slash ()
(dolist (fooslashalias '("foo/" "foo//" "foo/." "foo//." "foo///././."
"foo/a/.."))