unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Aleksandr Vityazev <avityazev@posteo.org>
To: 51754@debbugs.gnu.org
Subject: bug#51754: 29.0.50; [PATCH] tramp-compat-file-name-concat work in wrong way
Date: Wed, 10 Nov 2021 18:56:49 +0000	[thread overview]
Message-ID: <87czn7hma6.fsf@posteo.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1721 bytes --]

Hello, 

The current implementation of the tramp-compat-file-name-concat 
from lisp/net/tramp-compat.el fails test fileio-tests/file-name-concat
from file test/src/fileio-tests.el for file-name-concat on Emacs where no
file-name-concat.

#+begin_src elisp
(ert-deftest test-tramp-compat-file-name-concat ()
  (should (equal (tramp-compat-file-name-concat "foo" "bar") "foo/bar"))
  (should (equal (tramp-compat-file-name-concat "foo" "bar") "foo/bar"))
  (should (equal (tramp-compat-file-name-concat "foo" "bar" "zot") "foo/bar/zot"))
  (should (equal (tramp-compat-file-name-concat "foo/" "bar") "foo/bar"))
  (should (equal (tramp-compat-file-name-concat "foo//" "bar") "foo//bar"))
  (should (equal (tramp-compat-file-name-concat "foo/" "bar/" "zot") "foo/bar/zot"))
  (should (equal (tramp-compat-file-name-concat "fóo" "bar") "fóo/bar"))
  (should (equal (tramp-compat-file-name-concat "foo" "bár") "foo/bár"))
  (should (equal (tramp-compat-file-name-concat "fóo" "bár") "fóo/bár"))
  (let ((string (make-string 5 ?a)))
    (should (not (multibyte-string-p string)))
    (aset string 2 255)
    (should (not (multibyte-string-p string)))
    (should (equal (tramp-compat-file-name-concat "fóo" string) "fóo/aa\377aa")))
  (should (equal (tramp-compat-file-name-concat "foo") "foo"))
  (should (equal (tramp-compat-file-name-concat "foo/") "foo/"))
  (should (equal (tramp-compat-file-name-concat "foo" "") "foo"))
  (should (equal (tramp-compat-file-name-concat "foo" "" "" "" nil) "foo"))
  (should (equal (tramp-compat-file-name-concat "" "bar") "bar"))
  (should (equal (tramp-compat-file-name-concat "" "") "")))

(ert 'test-tramp-compat-file-name-concat)
#+end_src


[-- Attachment #2: test-tramp-compat-file-name-concat --]
[-- Type: text/plain, Size: 281 bytes --]

Selector: test-tramp-compat-file-name-concat
Passed:  0
Failed:  1 (1 unexpected)
Skipped: 0
Total:   1/1

Started at:   2021-11-10 21:21:24+0300
Finished.
Finished at:  2021-11-10 21:21:25+0300

F

F test-tramp-compat-file-name-concat
    (wrong-type-argument characterp "zot")



[-- Attachment #3: Type: text/plain, Size: 27 bytes --]


Here is the patch to fix:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: tramp-compat-file-name-concat --]
[-- Type: text/x-patch, Size: 1705 bytes --]

From 1a0c540abfc129d67bf2e291c038c2163f7fee7f Mon Sep 17 00:00:00 2001
From: Aleksandr Vityazev <avityazev@posteo.org>
Date: Wed, 10 Nov 2021 21:36:16 +0300
Subject: [PATCH] * lisp/net/tramp-compat.el: Fix tramp-compat-file-name-concat

* lisp/net/tramp-compat.el: Make tramp-compat-file-name-concat
work like file-name-concat.
---
 lisp/net/tramp-compat.el | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 213ab5857c..fbc3d684ce 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -386,14 +386,17 @@ CONDITION can also be a list of error conditions."
   (if (fboundp 'file-name-concat)
       #'file-name-concat
     (lambda (directory &rest components)
-      (unless (null directory)
-	(let ((components (delq nil components))
-	      file-name-handler-alist)
-	  (if (null components)
-	      directory
-	    (tramp-compat-file-name-concat
-	     (concat (file-name-as-directory directory) (car components))
-	     (cdr components))))))))
+      (let ((components (cl-remove-if (lambda (el)
+                                        (or (null el) (equal "" el)))
+                                      components))
+	    file-name-handler-alist)
+        (if (null components)
+	    directory
+          (apply #'tramp-compat-file-name-concat
+	         (concat (unless (or (equal "" directory) (null directory))
+                           (file-name-as-directory directory))
+                         (car components))
+	         (cdr components)))))))
 
 (dolist (elt (all-completions "tramp-compat-" obarray 'functionp))
   (put (intern elt) 'tramp-suppress-trace t))
-- 
2.33.1


[-- Attachment #5: Type: text/plain, Size: 39 bytes --]



-- 
Best regards,
Aleksandr Vityazev

             reply	other threads:[~2021-11-10 18:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 18:56 Aleksandr Vityazev [this message]
2021-11-11 10:59 ` bug#51754: 29.0.50; [PATCH] tramp-compat-file-name-concat work in wrong way Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czn7hma6.fsf@posteo.org \
    --to=avityazev@posteo.org \
    --cc=51754@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).