diff options
| author | Ken Brown | 2019-07-08 18:37:33 -0400 |
|---|---|---|
| committer | Ken Brown | 2019-07-08 18:37:33 -0400 |
| commit | 0528a7c8725c7c28a6f2815802fcc089c2fe306f (patch) | |
| tree | 7becae40b631d84dc3676ff6dd4f7dbe73bce5af | |
| parent | 122198d2f1aaf0b74c102874cc9b04ae4789f54f (diff) | |
| download | emacs-0528a7c8725c7c28a6f2815802fcc089c2fe306f.tar.gz emacs-0528a7c8725c7c28a6f2815802fcc089c2fe306f.zip | |
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.
| -rw-r--r-- | src/fileio.c | 17 | ||||
| -rw-r--r-- | test/src/fileio-tests.el | 5 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/fileio.c b/src/fileio.c index 505e4ec33bf..8f23a305a52 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -804,7 +804,22 @@ the root directory. */) | |||
| 804 | 804 | ||
| 805 | /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ | 805 | /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ |
| 806 | if (NILP (default_directory)) | 806 | if (NILP (default_directory)) |
| 807 | default_directory = BVAR (current_buffer, directory); | 807 | { |
| 808 | Lisp_Object dir = BVAR (current_buffer, directory); | ||
| 809 | /* The buffer's default-directory should be absolute. If it | ||
| 810 | isn't, try to expand it relative to invocation-directory. | ||
| 811 | But we have to be careful to avoid an infinite loop, because | ||
| 812 | the code in emacs.c that sets Vinvocation_directory might | ||
| 813 | call Fexpand_file_name. */ | ||
| 814 | if (STRINGP (dir)) | ||
| 815 | { | ||
| 816 | if (!NILP (Ffile_name_absolute_p (dir))) | ||
| 817 | default_directory = dir; | ||
| 818 | else if (STRINGP (Vinvocation_directory) | ||
| 819 | && !NILP (Ffile_name_absolute_p (Vinvocation_directory))) | ||
| 820 | default_directory = Fexpand_file_name (dir, Vinvocation_directory); | ||
| 821 | } | ||
| 822 | } | ||
| 808 | if (! STRINGP (default_directory)) | 823 | if (! STRINGP (default_directory)) |
| 809 | { | 824 | { |
| 810 | #ifdef DOS_NT | 825 | #ifdef DOS_NT |
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index bd827e5498f..8788c830c94 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." | |||
| 126 | (should (equal c1 (char-before))) | 126 | (should (equal c1 (char-before))) |
| 127 | (should (equal c1 (char-after)))))) | 127 | (should (equal c1 (char-after)))))) |
| 128 | (if f (delete-file f))))) | 128 | (if f (delete-file f))))) |
| 129 | |||
| 130 | (ert-deftest fileio-tests--relative-default-directory () | ||
| 131 | "Test expand-file-name when default-directory is relative." | ||
| 132 | (let ((default-directory "some/relative/name")) | ||
| 133 | (should (file-name-absolute-p (expand-file-name "foo"))))) | ||