From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Samer Masterson Newsgroups: gmane.emacs.bugs Subject: bug#8531: 24.0.50; Date: Sun, 05 Apr 2015 20:50:50 -0700 Message-ID: <1428292250.15170.0@mail.samertm.com> References: <1424775089.11596.4@mail.samertm.com> <83d24qqdsq.fsf@gnu.org> <1425472710.1450.3@mail.samertm.com> <83h9u0psn8.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 1428292345 3191 80.91.229.3 (6 Apr 2015 03:52:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Apr 2015 03:52:25 +0000 (UTC) Cc: 8531@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 06 05:52:12 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1Yey55-0007q1-4A for geb-bug-gnu-emacs@m.gmane.org; Mon, 06 Apr 2015 05:52:11 +0200 Original-Received: from localhost ([::1]:38230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yey54-0004on-A7 for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Apr 2015 23:52:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yey4z-0004oi-UK for bug-gnu-emacs@gnu.org; Sun, 05 Apr 2015 23:52:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yey4w-0004Zz-N2 for bug-gnu-emacs@gnu.org; Sun, 05 Apr 2015 23:52:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yey4w-0004Zv-Jl for bug-gnu-emacs@gnu.org; Sun, 05 Apr 2015 23:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yey4w-0004zq-78 for bug-gnu-emacs@gnu.org; Sun, 05 Apr 2015 23:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Samer Masterson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Apr 2015 03:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8531 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 8531-submit@debbugs.gnu.org id=B8531.142829227319142 (code B ref 8531); Mon, 06 Apr 2015 03:52:02 +0000 Original-Received: (at 8531) by debbugs.gnu.org; 6 Apr 2015 03:51:13 +0000 Original-Received: from localhost ([127.0.0.1]:45744 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yey48-0004yf-9P for submit@debbugs.gnu.org; Sun, 05 Apr 2015 23:51:12 -0400 Original-Received: from ec2-52-0-7-12.compute-1.amazonaws.com ([52.0.7.12]:55346 helo=samertm.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yey46-0004yS-4o for 8531@debbugs.gnu.org; Sun, 05 Apr 2015 23:51:10 -0400 Original-Received: from [10.20.0.210] (75-101-62-71.dsl.static.fusionbroadband.com [75.101.62.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by samertm.com (Postfix) with ESMTPSA id E078541B6B; Mon, 6 Apr 2015 03:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samertm.com; s=mail; t=1428292219; bh=sUcccSoC9cFUnI/GlbDxPcsUwCq9GZAQV0MLpMC8SEI=; h=Date:From:Subject:To:Cc:In-Reply-To:References:From; b=X4nvTS96L6eMhoPUriHxMTqOVBSwsYB8htPhrJuj6iRdAW6QIn4bh5aVlAqsA/O7p ItKYCKJ+G8MsvocH6yr4atJenuxFG2MO1VIVahrnhKhL7wXBOhh5bBwAzJBzMcwnuY BDwnzkRkndQMdPTKcwd8jZGWKtM4Nc45ivPfa38E= In-Reply-To: <83h9u0psn8.fsf@gnu.org> X-Mailer: geary/0.9.1 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:101222 Archived-At: Hi, This is the updated patch. Thanks in advance for the review. Just to clarify, the bug is that $ ls Vid\=C3=A9os doesn't do the right thing in eshell (it preserves the backslash if the character after it is non-special). This diverges from POSIX and Bash. New behavior: Outside of a double quoted string, the backslash escapes the following charater if that character is special. Otherwise it simply returns the character afterwards (the backslash is ignored). I expanded `eshell-parse-backslash's behavior to match Bash for quoted strings as well. Inside a double quoted string, the backslash escapes the following character if that character is special, otherwise the backslash is preserved. Best, Samer (The date on the commit below is correct, I just forgot to send it to the list). patch below: 900b7a998e210ec260b136ea093c3eba3ce63f34 HEAD bug-8531 Author: Samer Masterson Date: Sun Mar 15 04:01:58 2015 -0700 Fix bug#8531 =20 * eshell/esh-arg.el (eshell-parse-argument-hook): Update comment. (eshell-parse-backslash): Return escaped character after backslash if it is special. Otherwise, if the backslash is not in a quoted string, ignore the backslash and return the character after; if the backslash is in a quoted string, return the backslash and the character after. (bug#8531) * automated/eshell.el (eshell-test/escape-nonspecial) (eshell-test/escape-nonspecial-unicode) (eshell-test/escape-nonspecial-quoted) (eshell-test/escape-special-quoted): Add tests for new `eshell-parse-backslash' behavior. (bug#8531) 4 files changed, 69 insertions(+), 28 deletions(-) lisp/ChangeLog | 9 +++++++++ lisp/eshell/esh-arg.el | 49 +++++++++++++++++++++-----------------------= ---- test/ChangeLog | 8 ++++++++ test/automated/eshell.el | 31 ++++++++++++++++++++++++++++++ Modified lisp/ChangeLog diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a9cf1b0..209382d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2015-03-15 Samer Masterson + + * eshell/esh-arg.el (eshell-parse-argument-hook): Update comment. + (eshell-parse-backslash): Return escaped character after backslash + if it is special. Otherwise, if the backslash is not in a quoted + string, ignore the backslash and return the character after; if + the backslash is in a quoted string, return the backslash and the + character after. (bug#8531) + 2015-03-14 Michael R. Mauger =20 * progmodes/sql.el: Version 3.5 Modified lisp/eshell/esh-arg.el diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el index 5c7d7ca..a5f697f 100644 --- a/lisp/eshell/esh-arg.el +++ b/lisp/eshell/esh-arg.el @@ -89,7 +89,7 @@ yield the values intended." (goto-char (match-end 0)) (eshell-finish-arg))))) =20 - ;; backslash before a special character means escape it + ;; parse backslash and the character after 'eshell-parse-backslash =20 ;; text beginning with ' is a literally quoted @@ -305,34 +305,27 @@ If the character is itself a backslash, it needs no e= scaping." (string ?\\ char))))) =20 (defun eshell-parse-backslash () - "Parse a single backslash (\) character, which might mean escape. -It only means escape if the character immediately following is a -special character that is not itself a backslash." + "Parse a single backslash (\\) character and the character after. +If the character after the backslash is special, always ignore +the backslash and return the escaped character. + +Otherwise, if the backslash is not in quoted string, the +backslash is ignored and the character after is returned. If the +backslash is in a quoted string, the backslash and the character +after are both returned." (when (eq (char-after) ?\\) - (if (eshell-looking-at-backslash-return (point)) - (throw 'eshell-incomplete ?\\) - (if (and (not (eq (char-after (1+ (point))) ?\\)) - (if eshell-current-quoted - (memq (char-after (1+ (point))) - eshell-special-chars-inside-quoting) - (memq (char-after (1+ (point))) - eshell-special-chars-outside-quoting))) - (progn - (forward-char 2) - (list 'eshell-escape-arg - (char-to-string (char-before)))) - ;; allow \\ to mean a literal "\" character followed by a - ;; normal return, rather than a backslash followed by a line - ;; continuation (i.e., "\\ + \n" rather than "\ + \\n"). This - ;; is necessary because backslashes in Eshell are not special - ;; unless they either precede something special, or precede a - ;; backslash that precedes something special. (Mainly this is - ;; done to make using backslash on Windows systems more - ;; natural-feeling). - (if (eshell-looking-at-backslash-return (1+ (point))) - (forward-char)) - (forward-char) - "\\")))) + (when (eshell-looking-at-backslash-return (point)) + (throw 'eshell-incomplete ?\\)) + (forward-char 2) ; Move one char past the backslash. + ;; If the char is in a quote, backslash only has special meaning + ;; if it is escaping a special char. + (if eshell-current-quoted + (if (memq (char-before) eshell-special-chars-inside-quoting) + (list 'eshell-escape-arg (char-to-string (char-before))) + (concat "\\" (char-to-string (char-before)))) + (if (memq (char-before) eshell-special-chars-outside-quoting) + (list 'eshell-escape-arg (char-to-string (char-before))) + (char-to-string (char-before)))))) =20 (defun eshell-parse-literal-quote () "Parse a literally quoted string. Nothing has special meaning!" Modified test/ChangeLog diff --git a/test/ChangeLog b/test/ChangeLog index 6a474e1..ff2cd60 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,11 @@ +2015-03-15 Samer Masterson + + * automated/eshell.el (eshell-test/escape-nonspecial) + (eshell-test/escape-nonspecial-unicode) + (eshell-test/escape-nonspecial-quoted) + (eshell-test/escape-special-quoted): Add tests for new + `eshell-parse-backslash' behavior. (bug#8531) + 2015-03-10 Jackson Ray Hamilton =20 * indent/js-indent-init-dynamic.js: Fix spelling error. Modified test/automated/eshell.el diff --git a/test/automated/eshell.el b/test/automated/eshell.el index d51355f..81898db 100644 --- a/test/automated/eshell.el +++ b/test/automated/eshell.el @@ -166,6 +166,37 @@ e.g. \"{(+ 1 2)} 3\" =3D> 3" (eshell-command-result-p "+ 1 2; + $_ 4" "3\n6\n"))) =20 +(ert-deftest eshell-test/escape-nonspecial () + "Test that \"\\c\" and \"c\" are equivalent when \"c\" is not a +special character." + (with-temp-eshell + (eshell-command-result-p "echo he\\llo" + "hello\n"))) + +(ert-deftest eshell-test/escape-nonspecial-unicode () + "Test that \"\\c\" and \"c\" are equivalent when \"c\" is a +unicode character (unicode characters are nonspecial by +definition)." + (with-temp-eshell + (eshell-command-result-p "echo Vid\\=C3=A9os" + "Vid=C3=A9os\n"))) + +(ert-deftest eshell-test/escape-nonspecial-quoted () + "Test that the backslash is preserved for escaped nonspecial +chars" + (with-temp-eshell + (eshell-command-result-p "echo \"h\\i\"" + ;; Backslashes are doubled for regexp. + "h\\\\i\n"))) + +(ert-deftest eshell-test/escape-special-quoted () + "Test that the backslash is not preserved for escaped special +chars" + (with-temp-eshell + (eshell-command-result-p "echo \"h\\\\i\"" + ;; Backslashes are doubled for regexp. + "h\\\\i\n"))) + (ert-deftest eshell-test/command-running-p () "Modeline should show no command running" (with-temp-eshell =