[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 0528a7c: Ensure that expand-file-name returns an ab
From: |
Ken Brown |
Subject: |
[Emacs-diffs] master 0528a7c: Ensure that expand-file-name returns an absolute file name |
Date: |
Mon, 8 Jul 2019 18:39:52 -0400 (EDT) |
branch: master
commit 0528a7c8725c7c28a6f2815802fcc089c2fe306f
Author: Ken Brown <address@hidden>
Commit: Ken Brown <address@hidden>
Ensure that expand-file-name returns an absolute file name
* src/fileio.c (Fexpand_file_name): Don't directly use the current
buffer's default-directory if it is relative. Instead replace it
by its expansion relative to invocation-directory. (Bug#36502)
* test/src/fileio-tests.el
(fileio-tests--relative-default-directory): New test.
---
src/fileio.c | 17 ++++++++++++++++-
test/src/fileio-tests.el | 5 +++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/fileio.c b/src/fileio.c
index 505e4ec..8f23a30 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -804,7 +804,22 @@ the root directory. */)
/* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */
if (NILP (default_directory))
- default_directory = BVAR (current_buffer, directory);
+ {
+ Lisp_Object dir = BVAR (current_buffer, directory);
+ /* The buffer's default-directory should be absolute. If it
+ isn't, try to expand it relative to invocation-directory.
+ But we have to be careful to avoid an infinite loop, because
+ the code in emacs.c that sets Vinvocation_directory might
+ call Fexpand_file_name. */
+ if (STRINGP (dir))
+ {
+ if (!NILP (Ffile_name_absolute_p (dir)))
+ default_directory = dir;
+ else if (STRINGP (Vinvocation_directory)
+ && !NILP (Ffile_name_absolute_p (Vinvocation_directory)))
+ default_directory = Fexpand_file_name (dir, Vinvocation_directory);
+ }
+ }
if (! STRINGP (default_directory))
{
#ifdef DOS_NT
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index bd827e5..8788c83 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -126,3 +126,8 @@ Also check that an encoding error can appear in a symlink."
(should (equal c1 (char-before)))
(should (equal c1 (char-after))))))
(if f (delete-file f)))))
+
+(ert-deftest fileio-tests--relative-default-directory ()
+ "Test expand-file-name when default-directory is relative."
+ (let ((default-directory "some/relative/name"))
+ (should (file-name-absolute-p (expand-file-name "foo")))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 0528a7c: Ensure that expand-file-name returns an absolute file name,
Ken Brown <=