From unknown Wed Jun 18 23:06:29 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#7711 <7711@debbugs.gnu.org> To: bug#7711 <7711@debbugs.gnu.org> Subject: Status: Patch for bug #7687 Reply-To: bug#7711 <7711@debbugs.gnu.org> Date: Thu, 19 Jun 2025 06:06:29 +0000 retitle 7711 Patch for bug #7687 reassign 7711 emacs submitter 7711 Flo severity 7711 normal tag 7711 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Dec 22 13:54:45 2010 Received: (at submit) by debbugs.gnu.org; 22 Dec 2010 18:54:45 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVTpk-0000E7-A1 for submit@debbugs.gnu.org; Wed, 22 Dec 2010 13:54:44 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVTpi-0000Dv-D6 for submit@debbugs.gnu.org; Wed, 22 Dec 2010 13:54:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVTw4-0000xe-AF for submit@debbugs.gnu.org; Wed, 22 Dec 2010 14:01:17 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:45361) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVTw4-0000xa-5x for submit@debbugs.gnu.org; Wed, 22 Dec 2010 14:01:16 -0500 Received: from [140.186.70.92] (port=32901 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVTw2-00063U-Fe for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2010 14:01:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVTw0-0000wW-O9 for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2010 14:01:14 -0500 Received: from mail-iy0-f169.google.com ([209.85.210.169]:54203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVTw0-0000w0-HH for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2010 14:01:12 -0500 Received: by iyj17 with SMTP id 17so4869542iyj.0 for ; Wed, 22 Dec 2010 11:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=6UTmVse2xhpsSPbpJuw86MS5V8FYPRQ1fROeeq6JKT8=; b=xVE45J6fxW95TyEY4X6J+FPk3JmfihUxDkco/A/xIhxylt8qqYN5EUyrHfFuYYkbtI Q9br+/J6ZT8YqftsytSEtpkwBSZePv8g8UoU5i43nB9HyW8LsFznQ1UGByKtL/gdeBdL koTLVf9eEylmzL1HF1S0s1l3OkXyHnwSXrpek= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=TuHBA18yvtKLQi7DdpvtdEQy0+jan4BaFMfGLaiPnnWW2gUVRltyAzV0T2/ygb9Uu/ ryaPLbLQyzGHWUe+6PorEBxqcVR1iZrNeI4ZGnDcRrRTCV6Qs5CL/X8h8UFF2zC7Qvz+ 5EX3knVY+arhOzEmoHuSgrijLlbjVjis0nHpc= Received: by 10.231.200.139 with SMTP id ew11mr7640392ibb.128.1293044471554; Wed, 22 Dec 2010 11:01:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.10.195 with HTTP; Wed, 22 Dec 2010 11:00:51 -0800 (PST) From: Flo Date: Wed, 22 Dec 2010 20:00:51 +0100 Message-ID: Subject: Patch for bug #7687 To: bug-gnu-emacs@gnu.org Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) What problem is solved by this patch =========================================== GNU bug report #7687 23.1.50; shell-quote-argument does not correctly quote newlines A copy of that bug report is at the end of this Email Why does the patch solve the probem =================================== Before shell-quote-argument quoted everything except POSIX filename characters with a leading backslash. The result of shell-quote-argument was that a new line in the input was 'quoted' with a backslash. A backslashed followed by a newline however means line continuation to POSIX shells. It is discarded by the shell. So the result after the shell was the empty string. The new version of shell-quote-argument treats newlines specially. They are quoted with single quotes. Same information again put differently: old version: input to shell-quote-argument: a newline output of shell-quote-argument = input to the shell: backslash followed by a newline result of shell's quoting mechanism: the emtpy string (due to line continuation) new version: input to shell-quote-argument: a newline output of shell-quote-argument = input to the shell: newline in single quotes result of shell's quoting mechanism: a newline Change Log =========== subr.el does not yet have a change log, so I put it here shell-quote-argument now correctly quotes newlines for POSIX shells Effect on other systems ======================== shell-quote-argument already distinguishes between different system types using system-type. I only changed the part that is concerned about POSIX shells. diff: old version (23.1.50) first, new version second ===================================================== $ gunzip /usr/share/emacs/23.1.50/lisp/subr.el.gz -c | diff -c - /home/emp8118035/.emacs.d/patches/subr.el *** STDIN Wed Dec 22 19:27:58 2010 --- /home/emp8118035/.emacs.d/patches/subr.el Mon Dec 20 17:28:30 2010 *************** *** 2391,2403 **** (concat "\"" result (substring argument start) "\"")) (if (equal argument "") "''" ! ;; Quote everything except POSIX filename characters. ! ;; This should be safe enough even for really weird shells. ! (let ((result "") (start 0) end) (while (string-match "[^-0-9a-zA-Z_./]" argument start) (setq end (match-beginning 0) result (concat result (substring argument start end) ! "\\" (substring argument end (1+ end))) start (1+ end))) (concat result (substring argument start)))))) --- 2391,2407 ---- (concat "\"" result (substring argument start) "\"")) (if (equal argument "") "''" ! ;; Quote everything except POSIX filename characters. This should be safe ! ;; enough even for really weird shells. Quoting is done with backslash, ! ;; except for newlines, which are quoted with single quotes; a ! ;; backslash-newline sequence is interpreted as line-continuation by the ! ;; shell and thus effectivly being ignored. ! (let ((result "") (start 0) end ch) (while (string-match "[^-0-9a-zA-Z_./]" argument start) (setq end (match-beginning 0) + ch (substring argument end (1+ end)) result (concat result (substring argument start end) ! (if (string= ch "\n") "'\n'" (concat "\\" ch))) start (1+ end))) (concat result (substring argument start)))))) Copy of the bug report =========================================== GNU bug report logs - #7687 23.1.50; shell-quote-argument does not correctly quote newlines Please write in English if possible, because the Emacs maintainers usually do not have translators to read other languages for them. Your bug report will be posted to the emacs-pretest-bug gnu.org mailing list. Please describe exactly what actions triggered the bug and the precise symptoms of the bug: When I run the following script: ---------------------------------- #!/bin/bash emacs -Q --batch eval='(shell-command (concat "echo " (shell-quote-argument "line1\nline2") " >tmpfile"))' cat tmpfile ---------------------------------- I expect the following content within 'tmpfile', i.e. exactly the string I passed to shell-quote-argument. ------------- line1 line2 ------------- Instead I get this: ------------- line1line2 ------------- I have not made any modification to Emacs. I made a patch and will send it as described in the Emacs manual in chapter 'Sending Patches for GNU Emacs'. If Emacs crashed, and you have the Emacs process in the gdb debugger, please include the output from the following gdb commands: `bt full' and `xbacktrace'. If you would like to further debug the crash, please read the file /usr/share/emacs/23.1.50/etc/DEBUG for instructions. In GNU Emacs 23.1.50.1 (i486-pc-linux-gnu, GTK+ Version 2.18.0) of 2009-09-27 on palmer, modified by Debian (emacs-snapshot package, version 1:20090909-1) Windowing system distributor `The X.Org Foundation', version 11.0.10706000 configured using `configure '--build' 'i486-linux-gnu' '--host' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/23.1.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1.50/site-lisp:/usr/share/emacs/site-lisp' '--with-x=yes' '--with-x-toolkit=gtk' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g -Wl,--as-needed' 'CPPFLAGS='' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_US.utf8 value of $XMODIFIERS: nil locale-coding-system: utf-8-unix default enable-multibyte-characters: t Major mode: Info Minor modes in effect: tooltip-mode: t tool-bar-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t global-auto-composition-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Recent input: M-x b u g - r e p o C-g C-h i C-h r C-s b u g C-s 2 C-v SPC M-x r e p o r t - e m a c s - b u Recent messages: uncompressing emacs-6.gz...done uncompressing emacs-7.gz...done uncompressing emacs-8.gz...done Mark saved where search started uncompressing emacs.gz...done uncompressing emacs-6.gz...done uncompressing emacs.gz...done uncompressing emacs-6.gz...done uncompressing emacs.gz...done uncompressing emacs-6.gz...done Load-path shadows: /usr/share/emacs/23.1.50/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup /usr/share/emacs/site-lisp/rst hides /usr/share/emacs/23.1.50/lisp/textmodes/rst From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 23 10:07:18 2010 Received: (at control) by debbugs.gnu.org; 23 Dec 2010 15:07:18 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVml6-0006P4-Ib for submit@debbugs.gnu.org; Thu, 23 Dec 2010 10:07:18 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.183] helo=ironport2-out.pppoe.ca) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PVml5-0006Ot-5F for control@debbugs.gnu.org; Thu, 23 Dec 2010 10:07:11 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkYGAAf2Ek3O+ILX/2dsb2JhbACWD44YdMEthUoEhGWOGw X-IronPort-AV: E=Sophos;i="4.60,219,1291611600"; d="scan'208";a="86383992" Received: from 206-248-130-215.dsl.teksavvy.com (HELO ceviche.home) ([206.248.130.215]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 23 Dec 2010 10:13:48 -0500 Received: by ceviche.home (Postfix, from userid 20848) id 3FCC96610E; Thu, 23 Dec 2010 10:13:48 -0500 (EST) From: Stefan Monnier To: control@debbugs.gnu.org Subject: Re: bug#7711: Patch for bug #7687 Message-ID: References: Date: Thu, 23 Dec 2010 10:13:48 -0500 In-Reply-To: (Flo's message of "Wed, 22 Dec 2010 20:00:51 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.1 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.1 (--) merge 7711 7687 tags 7711 +patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 21 12:59:41 2011 Received: (at 7711) by debbugs.gnu.org; 21 Jan 2011 17:59:42 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PgLGv-0006vm-M2 for submit@debbugs.gnu.org; Fri, 21 Jan 2011 12:59:41 -0500 Received: from chene.dit.umontreal.ca ([132.204.246.20]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PgLGs-0006vV-IN; Fri, 21 Jan 2011 12:59:39 -0500 Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id p0LI7sNw028531; Fri, 21 Jan 2011 13:07:55 -0500 Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id F3A2CB411E; Fri, 21 Jan 2011 13:07:30 -0500 (EST) From: Stefan Monnier To: Flo Subject: Re: bug#7711: Patch for bug #7687 Message-ID: References: Date: Fri, 21 Jan 2011 13:07:30 -0500 In-Reply-To: (Flo's message of "Wed, 22 Dec 2010 20:00:51 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Level: X-NAI-Spam-Score: 0.7 X-NAI-Spam-Rules: 2 Rules triggered SUBJ_HAS_UNIQ_ID=0.7, RV3735=0 X-Spam-Score: -2.0 (--) X-Debbugs-Envelope-To: 7711 Cc: 7711@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.0 (--) forcemerge 7687 7711 close 7711 thanks > the empty string. The new version of shell-quote-argument > treats newlines specially. They are quoted with single > quotes. Thanks. I've installed a slightly different patch (took the opportunity to simplify the code by using replace-regexp-in-string) that implements your idea. Stefan === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2011-01-21 05:04:45 +0000 +++ lisp/ChangeLog 2011-01-21 18:04:16 +0000 @@ -1,3 +1,8 @@ +2011-01-21 Stefan Monnier + + * subr.el (shell-quote-argument): Properly quote \n (bug#7687). + Suggested by Flo . + 2011-01-21 Glenn Morris * progmodes/compile.el (compilation-error-regexp-alist): === modified file 'lisp/subr.el' --- lisp/subr.el 2011-01-15 02:32:19 +0000 +++ lisp/subr.el 2011-01-21 18:04:45 +0000 @@ -2426,13 +2426,8 @@ "''" ;; Quote everything except POSIX filename characters. ;; This should be safe enough even for really weird shells. - (let ((result "") (start 0) end) - (while (string-match "[^-0-9a-zA-Z_./]" argument start) - (setq end (match-beginning 0) - result (concat result (substring argument start end) - "\\" (substring argument end (1+ end))) - start (1+ end))) - (concat result (substring argument start)))))) + (replace-regexp-in-string "\n" "'\n'" + (replace-regexp-in-string "[^-0-9a-zA-Z_./\n]" "\\\\\\&" argument))))) (defun string-or-null-p (object) "Return t if OBJECT is a string or nil. From unknown Wed Jun 18 23:06:29 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 19 Feb 2011 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator