From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add shell-quasiquote. Date: Sat, 17 Oct 2015 22:43:26 +0200 Message-ID: <87eggtusy9.fsf@T420.taylan> References: <87si59wj42.fsf@T420.taylan> <83eggt4esi.fsf@gnu.org> <87a8rh2tpp.fsf@fastmail.com> <837fml46w6.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1445114635 28570 80.91.229.3 (17 Oct 2015 20:43:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Oct 2015 20:43:55 +0000 (UTC) Cc: Random832 , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 17 22:43:54 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZnYKV-0002bq-Lc for ged-emacs-devel@m.gmane.org; Sat, 17 Oct 2015 22:43:51 +0200 Original-Received: from localhost ([::1]:59693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnYKU-0005Tn-MK for ged-emacs-devel@m.gmane.org; Sat, 17 Oct 2015 16:43:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnYK9-0005TI-E5 for emacs-devel@gnu.org; Sat, 17 Oct 2015 16:43:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZnYK8-0006qL-HM for emacs-devel@gnu.org; Sat, 17 Oct 2015 16:43:29 -0400 Original-Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:34344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZnYK8-0006qD-An; Sat, 17 Oct 2015 16:43:28 -0400 Original-Received: by wikq8 with SMTP id q8so3740327wik.1; Sat, 17 Oct 2015 13:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=qZ2n9eO/oJ+ZkB+hDYpbfWDEVI7cNC0ure0d3IZz9NI=; b=iVYV1l2R5sAg2kl+bHmbtBwFid5hRE6QuqS6/Xphhmj4XoF+m5Tkd7uB4hjoteMq86 qFepl4tocdn6AWn//mt4n4KouvEy0eexWv1RtNEJa8dK5JLkW/CsZ9eS66+DJt3O/K91 KgeMEjxDGTguK6/2IeBeGPHKF3z98HPMgnkY9J9bOf67pup1X0K7wtXs+ouMPRyd7omh IyG7h6JK5VnH6Xo3FKfeRNmzumlKp4boBRFTBWiF/cXoCWIsGSDzjAYh0Q8OGRcwkW/5 yGTwlMEBWBokUfxA+13QA29I/gyLAxJ5ocI8dGt0DvIcporuwUpbm1szNDwBbFhZG51l f/Zw== X-Received: by 10.180.211.39 with SMTP id mz7mr12305667wic.65.1445114607788; Sat, 17 Oct 2015 13:43:27 -0700 (PDT) Original-Received: from T420.taylan ([2a02:908:c32:4740:221:ccff:fe66:68f0]) by smtp.gmail.com with ESMTPSA id r4sm8385246wia.19.2015.10.17.13.43.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 13:43:27 -0700 (PDT) In-Reply-To: <837fml46w6.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 17 Oct 2015 22:44:25 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:191879 Archived-At: Eli Zaretskii writes: >> From: Random832 >> Date: Sat, 17 Oct 2015 15:14:26 -0400 >>=20 >> Eli Zaretskii writes: >> >> From: taylanbayirli@gmail.com (Taylan Ulrich Bay=C4=B1rl=C4=B1/Kammer) >> >> +;;; Like `shell-quote-argument', but much simpler in implementation. >> >> +(defun shqq--quote-string (string) >> >> + (concat "'" (replace-regexp-in-string "'" "'\\\\''" string) "'")) >> > >> > It might be simpler, but it's wrong, because the result is only >> > correct for Posix shells. >> > >> > Please do use shell-quote-argument instead. >>=20 >> It's also simpler than the POSIX section of shell-quote-argument. > > Simpler doesn't mean correct. It doesn't, but anyone who knows POSIX shell grammar well should know that wrapping a string in '', and escaping literal "'"s by turning them into "'\''" (close so-far single quote, add backslash-escaped single quote, reopen single quote) is absolutely safe, because absolutely no character within two single quotes has a special meaning (one cannot even escape a single quote within two single quotes, hence the close/insert/reopen). >> (defun shell-quote-argument (argument) >> [...] (cond [...] (t >> (if (equal argument "") >> "''" >> ;; Quote everything except POSIX filename characters. >> ;; This should be safe enough even for really weird shells. >> (replace-regexp-in-string >> "\n" "'\n'" >> (replace-regexp-in-string "[^-0-9a-zA-Z_./\n]" "\\\\\\&" argument= )))))) >>=20 >> I wonder what "really weird shells" this refers to? > > The set of characters special to an arbitrary shell is not known in > advance. Yet that piece of code assumes a certain semantics for foo\bar (which is that the newline after the backslash is removed instead of interpreted literally) and special-handles that case, but doesn't attempt to handle other possible special meanings. Of course, I'm being pedantic here. This implementation is probably as safe as mine. I'm more worried about the non-POSIX variants because I have no clue of any non-POSIX shell syntax. Taylan