From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#26911: 25.2; eshell "cd .." doesn't work correctly with TRAMP Date: Thu, 27 Aug 2020 14:53:52 -0700 Organization: UCLA Computer Science Department Message-ID: <693aa189-03fa-b963-89eb-ce19c51ba325@cs.ucla.edu> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BB795A76905C5F289D9E0259" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37418"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Cc: 26911@debbugs.gnu.org, Michael Albinus , Yegor Timoshenko To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 27 23:55:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kBPrT-0009cf-FE for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 Aug 2020 23:55:11 +0200 Original-Received: from localhost ([::1]:49406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBPrR-0004nn-VU for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 Aug 2020 17:55:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBPrK-0004nc-25 for bug-gnu-emacs@gnu.org; Thu, 27 Aug 2020 17:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kBPrJ-0002PJ-OD for bug-gnu-emacs@gnu.org; Thu, 27 Aug 2020 17:55:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kBPrJ-0003MM-NP for bug-gnu-emacs@gnu.org; Thu, 27 Aug 2020 17:55:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 Aug 2020 21:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26911 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 26911-submit@debbugs.gnu.org id=B26911.159856524312839 (code B ref 26911); Thu, 27 Aug 2020 21:55:01 +0000 Original-Received: (at 26911) by debbugs.gnu.org; 27 Aug 2020 21:54:03 +0000 Original-Received: from localhost ([127.0.0.1]:44351 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kBPqM-0003L1-RQ for submit@debbugs.gnu.org; Thu, 27 Aug 2020 17:54:03 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kBPqK-0003KW-9o for 26911@debbugs.gnu.org; Thu, 27 Aug 2020 17:54:01 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7F8C8160112; Thu, 27 Aug 2020 14:53:54 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id f_oVfAtns7AW; Thu, 27 Aug 2020 14:53:53 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 46E3E160113; Thu, 27 Aug 2020 14:53:53 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vNBb2i6VuVNb; Thu, 27 Aug 2020 14:53:53 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-75-82-69-226.socal.res.rr.com [75.82.69.226]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id EFAEF160112; Thu, 27 Aug 2020 14:53:52 -0700 (PDT) Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkV5QWNtUUJFQURB QXlIMnhvVHU3cHBHNUQzYThGTVpFb243NGRDdmM0K3ExWEEySjJ0QnkycHdhVHFmCmhweHhk R0E5Smo1MFVKM1BENGJTVUVnTjh0TFowc2FuNDdsNVhUQUZMaTI0NTZjaVNsNW04c0thSGxH ZHQ5WG0KQUF0bVhxZVpWSVlYL1VGUzk2ZkR6ZjR4aEVtbS95N0xiWUVQUWRVZHh1NDd4QTVL aFRZcDVibHRGM1dZRHoxWQpnZDdneDA3QXV3cDdpdzdlTnZub0RUQWxLQWw4S1lEWnpiRE5D UUdFYnBZM2VmWkl2UGRlSStGV1FONFcra2doCnkrUDZhdTZQcklJaFlyYWV1YTdYRGRiMkxT MWVuM1NzbUUzUWpxZlJxSS9BMnVlOEpNd3N2WGUvV0szOEV6czYKeDc0aVRhcUkzQUZINmls QWhEcXBNbmQvbXNTRVNORnQ3NkRpTzFaS1FNcjlhbVZQa25qZlBtSklTcWRoZ0IxRApsRWR3 MzRzUk9mNlY4bVp3MHhmcVQ2UEtFNDZMY0ZlZnpzMGtiZzRHT1JmOHZqRzJTZjF0azVlVThN Qml5Ti9iClowM2JLTmpOWU1wT0REUVF3dVA4NGtZTGtYMndCeHhNQWhCeHdiRFZadWR6eERa SjFDMlZYdWpDT0pWeHEya2wKakJNOUVUWXVVR3FkNzVBVzJMWHJMdzYrTXVJc0hGQVlBZ1Jy NytLY3dEZ0JBZndoU In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:186575 Archived-At: This is a multi-part message in MIME format. --------------BB795A76905C5F289D9E0259 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 8/27/20 11:31 AM, Mattias Engdeg=C3=A5rd wrote: > No doubt the change (14fb657ba82) is fine in isolation, but now if Emac= s is started from $HOME/somedir and I do find-file, the minibuffer prompt= is "/home/mattias/somedir/" instead of "~/somedir/" which does not seem = to be an improvement. >=20 > Worse, if cwd is $HOME, the minibuffer prompt becomes "~" instead of "~= /" which is inconvenient since that slash has to be typed explicitly. Thanks for reporting that. Sigh, too often when I fix one bug in=20 expand-file-name I introduce another. I installed the attached patch to f= ix this=20 bug (I and I hope it doesn't introduce yet another :-). --------------BB795A76905C5F289D9E0259 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-recently-introduced-expand-file-name-bug.patch" Content-Disposition: attachment; filename="0001-Fix-recently-introduced-expand-file-name-bug.patch" Content-Transfer-Encoding: quoted-printable >From 0bbc84630f12e848e19c39dce01f3d14559bf70b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 27 Aug 2020 14:46:52 -0700 Subject: [PATCH] Fix recently-introduced expand-file-name bug MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit The bug was that (expand-file-name "~") returned something like "/home/eggert/" instead of "/home/eggert". Problem reported by Mattias Engdeg=C3=A5rd (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 =E2=80=98target[length] =3D = 0;=E2=80=99 as that byte will be overwritten by the next memcpy anyway. * test/src/fileio-tests.el (fileio-tests--HOME-trailing-slash): New test. --- src/fileio.c | 38 +++++++++++++------------------------- test/src/fileio-tests.el | 8 ++++++++ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index b70dff1c22..47e5e46a00 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -827,9 +827,9 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpand= _file_name, 1, 2, 0, ptrdiff_t tlen; #ifdef DOS_NT int drive =3D 0; - bool collapse_newdir =3D true; bool is_escaped =3D 0; #endif /* DOS_NT */ + bool collapse_newdir =3D true; ptrdiff_t length, nbytes; Lisp_Object handler, result, handled_name; bool multibyte; @@ -1183,9 +1183,7 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpa= nd_file_name, 1, 2, 0, newdir =3D SSDATA (hdir); newdirlim =3D newdir + SBYTES (hdir); } -#ifdef DOS_NT collapse_newdir =3D false; -#endif } else /* ~user/filename */ { @@ -1205,9 +1203,7 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexpa= nd_file_name, 1, 2, 0, =20 while (*++nm && !IS_DIRECTORY_SEP (*nm)) continue; -#ifdef DOS_NT collapse_newdir =3D false; -#endif } =20 /* If we don't find a user of that name, leave the name @@ -1374,12 +1370,7 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sexp= and_file_name, 1, 2, 0, } #endif /* DOS_NT */ =20 - /* Ignore any slash at the end of newdir, unless newdir is - just "/" or "//". */ length =3D newdirlim - newdir; - while (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1]) - && ! (length =3D=3D 2 && IS_DIRECTORY_SEP (newdir[0]))) - length--; =20 /* Now concatenate the directory and name to new space in the stack fr= ame. */ tlen =3D length + file_name_as_directory_slop + (nmlim - nm) + 1; @@ -1398,25 +1389,22 @@ DEFUN ("expand-file-name", Fexpand_file_name, Sex= pand_file_name, 1, 2, 0, =20 if (newdir) { - if (IS_DIRECTORY_SEP (nm[0])) + if (!collapse_newdir) { -#ifdef DOS_NT - /* If newdir is effectively "C:/", then the drive letter will have - been stripped and newdir will be "/". Concatenating with an - absolute directory in nm produces "//", which will then be - incorrectly treated as a network share. Ignore newdir in - this case (keeping the drive letter). */ - if (!(drive && nm[0] && IS_DIRECTORY_SEP (newdir[0]) - && newdir[1] =3D=3D '\0')) -#endif - { - memcpy (target, newdir, length); - target[length] =3D 0; - nbytes =3D length; - } + /* With ~ or ~user, leave NEWDIR as-is to avoid transforming + it from a symlink (or a regular file!) into a directory. */ + memcpy (target, newdir, length); + nbytes =3D length; } else nbytes =3D file_name_as_directory (target, newdir, length, multibyte); + + /* If TARGET ends in a directory separator, omit leading + directory separators from NM so that concatenating a TARGET "/" + to an NM "/foo" does not result in the incorrect "//foo". */ + if (nbytes && IS_DIRECTORY_SEP (target[nbytes - 1])) + while (IS_DIRECTORY_SEP (nm[0])) + nm++; } =20 memcpy (target + nbytes, nm, nmlim - nm + 1); diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index 1516590795..8b76912f5e 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -108,6 +108,14 @@ fileio-tests--relative-HOME (should (equal (expand-file-name "~/bar") "x:/foo/bar"))) (setenv "HOME" old-home))) =20 +(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/..")) --=20 2.17.1 --------------BB795A76905C5F289D9E0259--