GNU bug report logs - #71935
split-string-and-unquote mishandles dired-listing-switches with '

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Juri Linkov <juri@HIDDEN>; Done: Juri Linkov <juri@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 30.0.60, send any further explanations to 71935 <at> debbugs.gnu.org and Juri Linkov <juri@HIDDEN> Request was from Juri Linkov <juri@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 7 Jul 2024 07:01:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jul 07 03:01:40 2024
Received: from localhost ([127.0.0.1]:47194 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sQLu0-0005iO-8j
	for submit <at> debbugs.gnu.org; Sun, 07 Jul 2024 03:01:40 -0400
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:43551)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>)
 id 1sQLty-0005i9-Np; Sun, 07 Jul 2024 03:01:39 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 21D2AE0004;
 Sun,  7 Jul 2024 07:01:07 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
In-Reply-To: <86wmm16kuz.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 04 Jul
 2024 22:03:00 +0300")
Organization: LINKOV.NET
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
 <86tth52dkl.fsf@HIDDEN> <86wmm16kuz.fsf@HIDDEN>
Date: Sun, 07 Jul 2024 09:57:40 +0300
Message-ID: <86frslit97.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

close 71935 30.0.60
thanks

> Please install on the emacs-30 branch.

Installed.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 5 Jul 2024 07:44:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jul 05 03:44:04 2024
Received: from localhost ([127.0.0.1]:43520 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPdbw-0000bc-EJ
	for submit <at> debbugs.gnu.org; Fri, 05 Jul 2024 03:44:04 -0400
Received: from eggs.gnu.org ([209.51.188.92]:59170)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPdbu-0000as-FB
 for 71935 <at> debbugs.gnu.org; Fri, 05 Jul 2024 03:44:03 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPdbl-0007SA-UJ; Fri, 05 Jul 2024 03:43:53 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=rQWSOZL0X3069tqxz3LHN0a3QSAFjRys1xDQLSh89Ok=; b=JhjMxoDBdP2oTQ0FaSn1
 WMHfc48GPpKUXUKQbM2UndlD/Hl4yd0CaEwxlst37aOkL1/wI98zk/A4laVwq8L4ogOsHd/Dw3dLb
 n10aiHAI6PNndY+Scpfn3QR7LudWl0f6OhpKiXciUx3lMshTfvoJ9qwhyKY6EPIAAPwINQ8eJf6Dh
 OBJ2PJfGePk5yZic2vEDbkorCoZOoXBC9TRegEzaEtIuYcy6WJ5QjIc2hh7CzI5FIQwXMvT3P76+h
 ZCmt9b7mR1liqbZW71JSrDx/FOISSkTt+U9h/t3d2UvGE+AblkWi9L4XmZpjH6CBKA9D65rwqrI7V
 u7NWbS+iNUkPPg==;
Date: Fri, 05 Jul 2024 10:43:52 +0300
Message-Id: <86ed88707b.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86sewoqqpk.fsf@HIDDEN> (message from Juri Linkov on
 Fri, 05 Jul 2024 09:48:39 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
 <86tth52dkl.fsf@HIDDEN> <86wmm16kuz.fsf@HIDDEN>
 <86tth56kgw.fsf@HIDDEN> <86sewoqqpk.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Cc: 71935 <at> debbugs.gnu.org
> Date: Fri, 05 Jul 2024 09:48:39 +0300
> 
> >> Thanks, that's what I had in mind.  Please install on the emacs-30
> >> branch.
> >
> > On second thought: could there be options that include shell
> > wildcards, which therefore should not be quoted?  If so, perhaps
> > instead of shell-quote-argument we should use
> > shell-quote-wildcard-pattern?
> 
> Indeed, there are ls switches that use wildcards, e.g.
> ‘--hide=PATTERN’ and ‘--ignore=PATTERN’.  But it seems
> they are ignored anyway while using wildcards with 'ls -d',
> so I can't test them.  What I can confirm only is that with
> 
> 1. (setopt dired-listing-switches "-al --block-size='1 --ignore=system*")
> 2. C-x d /tmp/s*
> 
> the switches are correctly quoted by 'shell-quote-wildcard-pattern':
> 
> "ls -d --dired -N -al --block-size=\\'1 --ignore=system* -- s*"

Thanks.  So I think this is a better solution for this tricky problem.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 5 Jul 2024 06:56:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jul 05 02:56:18 2024
Received: from localhost ([127.0.0.1]:43454 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPcri-0007kP-9b
	for submit <at> debbugs.gnu.org; Fri, 05 Jul 2024 02:56:18 -0400
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:50695)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1sPcrg-0007k9-6r
 for 71935 <at> debbugs.gnu.org; Fri, 05 Jul 2024 02:56:16 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 4BD12240004;
 Fri,  5 Jul 2024 06:56:05 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
In-Reply-To: <86tth56kgw.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 04 Jul
 2024 22:11:27 +0300")
Organization: LINKOV.NET
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
 <86tth52dkl.fsf@HIDDEN> <86wmm16kuz.fsf@HIDDEN>
 <86tth56kgw.fsf@HIDDEN>
Date: Fri, 05 Jul 2024 09:48:39 +0300
Message-ID: <86sewoqqpk.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> > @@ -8195,9 +8193,11 @@ insert-directory
>> > -			       (if (stringp switches)
>> > -				   switches
>> > -				 (mapconcat #'identity switches " "))
>> > +			       (mapconcat #'shell-quote-argument
>> > +                                          (if (stringp switches)
>> > +				              (split-string-and-unquote switches)
>> > +                                            switches)
>> > +                                          " ")
>>
>> Thanks, that's what I had in mind.  Please install on the emacs-30
>> branch.
>
> On second thought: could there be options that include shell
> wildcards, which therefore should not be quoted?  If so, perhaps
> instead of shell-quote-argument we should use
> shell-quote-wildcard-pattern?

Indeed, there are ls switches that use wildcards, e.g.
‘--hide=PATTERN’ and ‘--ignore=PATTERN’.  But it seems
they are ignored anyway while using wildcards with 'ls -d',
so I can't test them.  What I can confirm only is that with

1. (setopt dired-listing-switches "-al --block-size='1 --ignore=system*")
2. C-x d /tmp/s*

the switches are correctly quoted by 'shell-quote-wildcard-pattern':

"ls -d --dired -N -al --block-size=\\'1 --ignore=system* -- s*"

diff --git a/lisp/files.el b/lisp/files.el
index 042b8e2d515..e69dfb22a5f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8195,9 +8193,15 @@ insert-directory
                                 "\\") ; Disregard Unix shell aliases!
                               insert-directory-program
                               " -d "
-                              (if (stringp switches)
-                                  switches
-                                (mapconcat #'identity switches " "))
+                              ;; Quote switches that require quoting
+                              ;; such as "--block-size='1".  But don't
+                              ;; quote switches that use patterns
+                              ;; such as "--ignore=PATTERN" (bug#71935).
+                              (mapconcat #'shell-quote-wildcard-pattern
+                                         (if (stringp switches)
+                                             (split-string-and-unquote switches)
+                                           switches)
+                                         " ")
                               " -- "
                               ;; Quote some characters that have
                               ;; special meanings in shells; but




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 19:12:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 15:12:05 2024
Received: from localhost ([127.0.0.1]:43000 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPRsD-0002eW-7J
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 15:12:05 -0400
Received: from eggs.gnu.org ([209.51.188.92]:55146)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPRsB-0002dv-6i
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 15:12:03 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPRs1-0003fp-UO; Thu, 04 Jul 2024 15:11:53 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=Q+5mBKgKHSC1Ck9BtM0DJ8JgFvJyj0AYYDHI8xg58xw=; b=ns55WOYn/l34
 UoGlGmv0OTs8k6A5p1W9LXwW/mU9tlAopqlqxr1N5btu7Wcl4sNdsYHD8QpgCRUODLVCO0+NBHmfE
 vbXW+aPtZAfld6gKleId1DPOLwD0RdS28aAuGfyj1xQskKvNdygnQgo46B65EdolfZjSM+cPdUlX6
 Vt3sIQxAoejq9wFYTw5qTn5qhmqZCkqI2KJBqhU8gfR6WTj9GsbsNttR5GRtKro5NaxRpC2YXD6Gj
 r6sglHcJ9iQZRHJiedxK92QZ++kbfWxro2HgmWlTgjcCm+rdJ/Rs7T3HAeublYpP9hRqCAywBTiQ8
 jtVQhoWjHb5fVO4DMGqZ7Q==;
Date: Thu, 04 Jul 2024 22:11:27 +0300
Message-Id: <86tth56kgw.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: juri@HIDDEN
In-Reply-To: <86wmm16kuz.fsf@HIDDEN> (message from Eli Zaretskii on Thu, 04
 Jul 2024 22:03:00 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
 <86tth52dkl.fsf@HIDDEN> <86wmm16kuz.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Cc: 71935 <at> debbugs.gnu.org
> Date: Thu, 04 Jul 2024 22:03:00 +0300
> From: Eli Zaretskii <eliz@HIDDEN>
> 
> > diff --git a/lisp/files.el b/lisp/files.el
> > index 042b8e2d515..6ed07f02890 100644
> > --- a/lisp/files.el
> > +++ b/lisp/files.el
> > @@ -8195,9 +8193,11 @@ insert-directory
> >  				 "\\") ; Disregard Unix shell aliases!
> >  			       insert-directory-program
> >  			       " -d "
> > -			       (if (stringp switches)
> > -				   switches
> > -				 (mapconcat #'identity switches " "))
> > +			       (mapconcat #'shell-quote-argument
> > +                                          (if (stringp switches)
> > +				              (split-string-and-unquote switches)
> > +                                            switches)
> > +                                          " ")
> >  			       " -- "
> >  			       ;; Quote some characters that have
> >  			       ;; special meanings in shells; but
> > 
> 
> Thanks, that's what I had in mind.  Please install on the emacs-30
> branch.

On second thought: could there be options that include shell
wildcards, which therefore should not be quoted?  If so, perhaps
instead of shell-quote-argument we should use
shell-quote-wildcard-pattern?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 19:05:25 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 15:05:25 2024
Received: from localhost ([127.0.0.1]:42994 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPRll-0002Tt-8k
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 15:05:25 -0400
Received: from eggs.gnu.org ([209.51.188.92]:48776)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPRlj-0002Tg-M3
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 15:05:24 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPRjU-00056Z-Fl; Thu, 04 Jul 2024 15:03:04 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=jaueSfvnOcYTYd9lzFIvebis1i5B4t+PU/sBmxzvfa0=; b=El9kQfASU96H
 RhdNaUxZhbElxNt+tIWfeAtAs+jhhkhFbk4PMLnezg5CbgTjFgyZFTmXTPxlJJJfDWRb3JtllQ1Im
 Kt2cXmT7yC7zrIYk/ZK6n17QEc9Lpi1OiDltbbnqGpwefvNJ09nD22nHWOWLyKgV9G3hw9P/qCscy
 5Q9ZydgtADDI8itAh5uE8pHKwUqLmjJXT9mS+/r49dqAZRv3VKUDlDKQlJXCPPw5egQwfhaGYZn3X
 WbzcmUq4uQVQR2RsUHIZO6u9OhsCQoqJsaFOVMl5gaEeptpN72K8IdhB7EjBe4IVqz6i2OZedLrGy
 aNLkwJvONLaDyEXalZ93cA==;
Date: Thu, 04 Jul 2024 22:03:00 +0300
Message-Id: <86wmm16kuz.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86tth52dkl.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 04 Jul 2024 21:54:02 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
 <86tth52dkl.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Cc: 71935 <at> debbugs.gnu.org
> Date: Thu, 04 Jul 2024 21:54:02 +0300
> 
> >>> 1. (setopt dired-listing-switches "-al --block-size='1")
> >>> 2. C-x d /tmp/*
> >
> > If they are a single string, split it with split-string-and-unquote,
> > then concatenate after running each one through shell-quote-argument.
> > If they are a list of strings, quote each one before concatenating
> > with mapconcat.
> 
> Ok, this seems to work:
> 
> diff --git a/lisp/files.el b/lisp/files.el
> index 042b8e2d515..6ed07f02890 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -8195,9 +8193,11 @@ insert-directory
>  				 "\\") ; Disregard Unix shell aliases!
>  			       insert-directory-program
>  			       " -d "
> -			       (if (stringp switches)
> -				   switches
> -				 (mapconcat #'identity switches " "))
> +			       (mapconcat #'shell-quote-argument
> +                                          (if (stringp switches)
> +				              (split-string-and-unquote switches)
> +                                            switches)
> +                                          " ")
>  			       " -- "
>  			       ;; Quote some characters that have
>  			       ;; special meanings in shells; but
> 

Thanks, that's what I had in mind.  Please install on the emacs-30
branch.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 18:57:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 14:57:30 2024
Received: from localhost ([127.0.0.1]:42989 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPRe6-0002Fn-B4
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:57:30 -0400
Received: from relay9-d.mail.gandi.net ([217.70.183.199]:48783)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1sPRe4-0002Fa-Qv
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:57:29 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id F3916FF802;
 Thu,  4 Jul 2024 18:57:19 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
In-Reply-To: <8634op80r5.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 04 Jul
 2024 21:34:22 +0300")
Organization: LINKOV.NET
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN> <8634op80r5.fsf@HIDDEN>
Date: Thu, 04 Jul 2024 21:54:02 +0300
Message-ID: <86tth52dkl.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>>> 1. (setopt dired-listing-switches "-al --block-size='1")
>>> 2. C-x d /tmp/*
>
> If they are a single string, split it with split-string-and-unquote,
> then concatenate after running each one through shell-quote-argument.
> If they are a list of strings, quote each one before concatenating
> with mapconcat.

Ok, this seems to work:

diff --git a/lisp/files.el b/lisp/files.el
index 042b8e2d515..6ed07f02890 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -8195,9 +8193,11 @@ insert-directory
 				 "\\") ; Disregard Unix shell aliases!
 			       insert-directory-program
 			       " -d "
-			       (if (stringp switches)
-				   switches
-				 (mapconcat #'identity switches " "))
+			       (mapconcat #'shell-quote-argument
+                                          (if (stringp switches)
+				              (split-string-and-unquote switches)
+                                            switches)
+                                          " ")
 			       " -- "
 			       ;; Quote some characters that have
 			       ;; special meanings in shells; but




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 18:34:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 14:34:47 2024
Received: from localhost ([127.0.0.1]:42959 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPRI7-0001dj-Gb
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:34:47 -0400
Received: from eggs.gnu.org ([209.51.188.92]:52402)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPRI2-0001dN-DP
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:34:46 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPRHt-0004n6-JR; Thu, 04 Jul 2024 14:34:33 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=RWY1RQfoUQwsGjzM60PYjQpWXKDGFxrEga9WhrESB6c=; b=k9Roxwdm0p+m
 2U+3GDzbqtOS4J1btN/JM7zNrkfY9BDBp8hv+M1+nYMsQ8VopDVYqcsssAIaJW5/+5w2oXgIA2T9Q
 HokxdLJbMuTGrk4nRLz6nJgFpIBKNjejyRilOgncvM7uuKWlg1nSMuyxnFBP4n6uJ2c0wLF+xprRu
 jGLn+hADvcGjHhvSrf9iNdLOpy5DH4oTds+yDxpBZQ9W+Hv5dU8A7IALmV/GBX096dkviGQp1T+Vh
 0IJcqUDgv6oT/k9bXdLmxyINtgloE7ltbplZifenTBl36LuO6JNYUP5M7/dKm7VDJuiPe10SN7KwL
 A6NuGqO1qjAEGo4NSh/Anw==;
Date: Thu, 04 Jul 2024 21:34:22 +0300
Message-Id: <8634op80r5.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
In-Reply-To: <8634opowlq.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 04 Jul 2024 21:12:01 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
 <8634opowlq.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Cc: 71935 <at> debbugs.gnu.org
> Date: Thu, 04 Jul 2024 21:12:01 +0300
> 
> >> >> 1. (setopt dired-listing-switches "-al --block-size='1")
> >> >> 2. C-x d /tmp/*
> >> 
> >> This part of insert-directory is used only in case of 1-2 above,
> >> i.e. for wildcard '/tmp/*'.  In this case the value of 'switches'
> >> is "--dired -N -al --block-size='1", and 'shell-quote-argument'
> >> returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails.
> >
> > I meant to call shell-quote-argument on each option, before they are
> > concatenated.
> 
> But switches are never unconcatenated in a list,
> they come from the string:
> 
>   (setopt dired-listing-switches "-al --block-size='1")

If they are a single string, split it with split-string-and-unquote,
then concatenate after running each one through shell-quote-argument.
If they are a list of strings, quote each one before concatenating
with mapconcat.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 18:13:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 14:13:16 2024
Received: from localhost ([127.0.0.1]:42933 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPQxI-00012o-3b
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:13:16 -0400
Received: from relay5-d.mail.gandi.net ([217.70.183.197]:40901)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1sPQx1-000123-Gr
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 14:13:14 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 190BE1C0002;
 Thu,  4 Jul 2024 18:12:49 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
In-Reply-To: <868qyh82is.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 04 Jul
 2024 20:56:11 +0300")
Organization: LINKOV.NET
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN> <868qyh82is.fsf@HIDDEN>
Date: Thu, 04 Jul 2024 21:12:01 +0300
Message-ID: <8634opowlq.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> >> 1. (setopt dired-listing-switches "-al --block-size='1")
>> >> 2. C-x d /tmp/*
>> 
>> This part of insert-directory is used only in case of 1-2 above,
>> i.e. for wildcard '/tmp/*'.  In this case the value of 'switches'
>> is "--dired -N -al --block-size='1", and 'shell-quote-argument'
>> returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails.
>
> I meant to call shell-quote-argument on each option, before they are
> concatenated.

But switches are never unconcatenated in a list,
they come from the string:

  (setopt dired-listing-switches "-al --block-size='1")

>> For the non-wildcard case of 3-4 above, this doesn't help either.
>> Using (mapcar 'shell-quote-argument (split-string-and-unquote switches))
>> on ("--dired" "-N" "-al" "--block-size=\\'1") returns
>> ("--dired" "-N" "-al" "--block-size\\=\\\\\\'1") that fails with
>> 
>>   /bin/ls: unrecognized option '--block-size\=\\\'1'
>
> Why did you use "--block-size=\\'1"?  My idea is that the quoting
> should not come from the user.

If the wildcard case above could be fixed, then there is no need
to use "--block-size=\\'1".




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 17:56:25 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 13:56:25 2024
Received: from localhost ([127.0.0.1]:42910 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPQgy-0000Zw-NE
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 13:56:25 -0400
Received: from eggs.gnu.org ([209.51.188.92]:33436)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPQgw-0000Ze-FQ
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 13:56:23 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPQgo-00054X-BB; Thu, 04 Jul 2024 13:56:14 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=/SKPPCbkX9u7vEpJYyhqZ6r7+O6kkRNA4s+ytH4uCbM=; b=DcB5eJ15IbD5pTxyuLlp
 mw+aUCCmfzf/ppbyIRay6MJNtRahcXKSPpc04c9JOPnnU6/8Xahy1HnBojJUpJXBpbuXxpjV04Tim
 z8rUKKK80TwKnrbKzKrb1i5ZQ6x6KYZd5HJwPMG27rKjDsdoTQDNs6qBDQi1pSFQ72sRbuaxTV+A3
 k7WRb6g/Z3+M587/Rq9Ow8q9rURh8gEVdAwC33milncxi3ZTmxylXGMWrMOjdYzF+U3PuynRybN4I
 zTG06xeDpzLUQhaQfxKwYuR/S+0yXQg/PvH+JLLT8K/ioDUxwlOgcaYgoi0PZo8eLbqPHl3mMNKOg
 VxBhy2LeUiLKdg==;
Date: Thu, 04 Jul 2024 20:56:11 +0300
Message-Id: <868qyh82is.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86a5ixqhd4.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 04 Jul 2024 19:10:17 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
 <86a5ixqhd4.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Cc: 71935 <at> debbugs.gnu.org
> Date: Thu, 04 Jul 2024 19:10:17 +0300
> 
> >> 1. (setopt dired-listing-switches "-al --block-size='1")
> >> 2. C-x d /tmp/*
> >>
> >>   /tmp:
> >>   wildcard *
> >>   /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
> >>   /bin/bash: -c: line 1: syntax error: unexpected end of file
> >>
> >> 3. (setopt dired-listing-switches "-al --block-size=\\'1")
> >> 4. C-x d /tmp/
> >>
> >> Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked")
> >>   error("Listing directory failed but `access-file' worked")
> >>   insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t)
> >
> > I think the part of insert-directory that deals with wildcard lacks
> > the call to shell-quote-argument here:
> >
> > 		      ;; NB since switches is passed to the shell, be
> > 		      ;; careful of malicious values, eg "-l;reboot".
> > 		      ;; See eg dired-safe-switches-p.
> > 		      (call-process
> > 		       shell-file-name nil t nil
> > 		       shell-command-switch
> > 		       (concat (if (memq system-type '(ms-dos windows-nt))
> > 				   ""
> > 				 "\\") ; Disregard Unix shell aliases!
> > 			       insert-directory-program
> > 			       " -d "
> > 			       (if (stringp switches)
> > 				   switches
> > 				 (mapconcat #'identity switches " "))
> >
> > Can you try running each switch through shell-quote-argument?
> 
> This part of insert-directory is used only in case of 1-2 above,
> i.e. for wildcard '/tmp/*'.  In this case the value of 'switches'
> is "--dired -N -al --block-size='1", and 'shell-quote-argument'
> returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails.

I meant to call shell-quote-argument on each option, before they are
concatenated.

> For the non-wildcard case of 3-4 above, this doesn't help either.
> Using (mapcar 'shell-quote-argument (split-string-and-unquote switches))
> on ("--dired" "-N" "-al" "--block-size=\\'1") returns
> ("--dired" "-N" "-al" "--block-size\\=\\\\\\'1") that fails with
> 
>   /bin/ls: unrecognized option '--block-size\=\\\'1'

Why did you use "--block-size=\\'1"?  My idea is that the quoting
should not come from the user.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 16:14:38 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 12:14:38 2024
Received: from localhost ([127.0.0.1]:42825 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPP6T-0006JL-MC
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 12:14:38 -0400
Received: from relay9-d.mail.gandi.net ([217.70.183.199]:32843)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1sPP6R-0006Is-Mh
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 12:14:36 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 9F60BFF80A;
 Thu,  4 Jul 2024 16:14:05 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
In-Reply-To: <86zfqx8tnn.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 04 Jul
 2024 11:10:04 +0300")
Organization: LINKOV.NET
References: <86tth5tztt.fsf@HIDDEN> <86zfqx8tnn.fsf@HIDDEN>
Date: Thu, 04 Jul 2024 19:10:17 +0300
Message-ID: <86a5ixqhd4.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> 1. (setopt dired-listing-switches "-al --block-size='1")
>> 2. C-x d /tmp/*
>>
>>   /tmp:
>>   wildcard *
>>   /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
>>   /bin/bash: -c: line 1: syntax error: unexpected end of file
>>
>> 3. (setopt dired-listing-switches "-al --block-size=\\'1")
>> 4. C-x d /tmp/
>>
>> Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked")
>>   error("Listing directory failed but `access-file' worked")
>>   insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t)
>
> I think the part of insert-directory that deals with wildcard lacks
> the call to shell-quote-argument here:
>
> 		      ;; NB since switches is passed to the shell, be
> 		      ;; careful of malicious values, eg "-l;reboot".
> 		      ;; See eg dired-safe-switches-p.
> 		      (call-process
> 		       shell-file-name nil t nil
> 		       shell-command-switch
> 		       (concat (if (memq system-type '(ms-dos windows-nt))
> 				   ""
> 				 "\\") ; Disregard Unix shell aliases!
> 			       insert-directory-program
> 			       " -d "
> 			       (if (stringp switches)
> 				   switches
> 				 (mapconcat #'identity switches " "))
>
> Can you try running each switch through shell-quote-argument?

This part of insert-directory is used only in case of 1-2 above,
i.e. for wildcard '/tmp/*'.  In this case the value of 'switches'
is "--dired -N -al --block-size='1", and 'shell-quote-argument'
returns "--dired\\ -N\\ -al\\ --block-size\\=\\'1" that fails.

For the non-wildcard case of 3-4 above, this doesn't help either.
Using (mapcar 'shell-quote-argument (split-string-and-unquote switches))
on ("--dired" "-N" "-al" "--block-size=\\'1") returns
("--dired" "-N" "-al" "--block-size\\=\\\\\\'1") that fails with

  /bin/ls: unrecognized option '--block-size\=\\\'1'




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at 71935 <at> debbugs.gnu.org:


Received: (at 71935) by debbugs.gnu.org; 4 Jul 2024 08:10:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 04:10:18 2024
Received: from localhost ([127.0.0.1]:41435 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPHXl-0006LN-TY
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 04:10:18 -0400
Received: from eggs.gnu.org ([209.51.188.92]:33068)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1sPHXj-0006L4-1i
 for 71935 <at> debbugs.gnu.org; Thu, 04 Jul 2024 04:10:16 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1sPHXa-0005aL-Dt; Thu, 04 Jul 2024 04:10:06 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From:
 Date; bh=f2HNcj1ddVwIzY5KQLZdGJwBqTNTeDY1rDb3A++zlKQ=; b=bMZoOw6AQ9+kN3FCQ4RA
 C6SuTq7Fznl1VcAuW2axXkXxi3nSoRNABR8uP6BbyTkBh7blgJp/P8DtAXMxAf1ATpmKb03Gme/AY
 cZOy+xpaaKKiDN/g8Uhc5HSWpbkr592jbkEE15whW33FdNAr69/UztpOHYTfhiPYY2IkgViTd9ena
 KW6Bvtnb37rsswvLanAraV2DRPFOlwTKKWmOzXVI1BUnEZ0cYMu1FAsDXji1OXOZ4Dl9pKfgS7n8W
 DKIqqHROlK66kvQ2X4ymCpSAQIWAq/RUUdXMUmrrFOsRPSPft6GTYICPIVPAT0GIS6KCh+M0/OPjp
 0qGsT7KRBLtT8A==;
Date: Thu, 04 Jul 2024 11:10:04 +0300
Message-Id: <86zfqx8tnn.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86tth5tztt.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 04 Jul 2024 09:51:10 +0300)
Subject: Re: bug#71935: split-string-and-unquote mishandles
 dired-listing-switches with '
References: <86tth5tztt.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 71935
Cc: 71935 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Date: Thu, 04 Jul 2024 09:51:10 +0300
> 
> 0. emacs -Q
> 1. (setopt dired-listing-switches "-al --block-size='1")
> 2. C-x d /tmp/*
> 
>   /tmp:
>   wildcard *
>   /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
>   /bin/bash: -c: line 1: syntax error: unexpected end of file
> 
> 3. (setopt dired-listing-switches "-al --block-size=\\'1")
> 4. C-x d /tmp/
> 
> Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked")
>   error("Listing directory failed but `access-file' worked")
>   insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t)
>   dired-insert-directory("/tmp/" "-al --block-size=\\'1" nil nil t)
>   dired-readin-insert()
>   dired-readin()
>   dired-internal-noselect("/tmp/" nil)
>   dired-noselect("/tmp/" nil)
>   dired("/tmp/" nil)
>   funcall-interactively(dired "/tmp/" nil)
>   command-execute(dired)
> 
> because 'split-string-and-unquote' in 'insert-directory'
> doesn't turn "--block-size=\\'1" into "--block-size='1".

I think the part of insert-directory that deals with wildcard lacks
the call to shell-quote-argument here:

		      ;; NB since switches is passed to the shell, be
		      ;; careful of malicious values, eg "-l;reboot".
		      ;; See eg dired-safe-switches-p.
		      (call-process
		       shell-file-name nil t nil
		       shell-command-switch
		       (concat (if (memq system-type '(ms-dos windows-nt))
				   ""
				 "\\") ; Disregard Unix shell aliases!
			       insert-directory-program
			       " -d "
			       (if (stringp switches)
				   switches
				 (mapconcat #'identity switches " "))

Can you try running each switch through shell-quote-argument?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Jul 2024 07:01:38 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 04 03:01:38 2024
Received: from localhost ([127.0.0.1]:41337 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sPGTK-0004Wq-4m
	for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 03:01:38 -0400
Received: from lists.gnu.org ([209.51.188.17]:48456)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1sPGTI-0004Wd-99
 for submit <at> debbugs.gnu.org; Thu, 04 Jul 2024 03:01:36 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1sPGTD-0001Aa-2w
 for bug-gnu-emacs@HIDDEN; Thu, 04 Jul 2024 03:01:32 -0400
Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1sPGTA-0001RE-3x
 for bug-gnu-emacs@HIDDEN; Thu, 04 Jul 2024 03:01:30 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id AE9E940004
 for <bug-gnu-emacs@HIDDEN>; Thu,  4 Jul 2024 07:01:24 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: split-string-and-unquote mishandles dired-listing-switches with '
Organization: LINKOV.NET
Date: Thu, 04 Jul 2024 09:51:10 +0300
Message-ID: <86tth5tztt.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
Received-SPF: pass client-ip=2001:4b98:dc4:8::222;
 envelope-from=juri@HIDDEN; helo=relay2-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.6 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

0. emacs -Q
1. (setopt dired-listing-switches "-al --block-size='1")
2. C-x d /tmp/*

  /tmp:
  wildcard *
  /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
  /bin/bash: -c: line 1: syntax error: unexpected end of file

3. (setopt dired-listing-switches "-al --block-size=\\'1")
4. C-x d /tmp/

Debugger entered--Lisp error: (error "Listing directory failed but ‘access-file’ worked")
  error("Listing directory failed but `access-file' worked")
  insert-directory("/tmp/" "--dired -N -al --block-size=\\'1" nil t)
  dired-insert-directory("/tmp/" "-al --block-size=\\'1" nil nil t)
  dired-readin-insert()
  dired-readin()
  dired-internal-noselect("/tmp/" nil)
  dired-noselect("/tmp/" nil)
  dired("/tmp/" nil)
  funcall-interactively(dired "/tmp/" nil)
  command-execute(dired)

because 'split-string-and-unquote' in 'insert-directory'
doesn't turn "--block-size=\\'1" into "--block-size='1".

5. (setopt dired-listing-switches "-al --block-size=\"'1\"")
6. C-x d /tmp/

Same error for another reason, because 'split-string-and-unquote'
splits "--block-size=\"'1\"" to '("--block-size=" "'1").




Acknowledgement sent to Juri Linkov <juri@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#71935; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 7 Jul 2024 07:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.