From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#37073: 26.2.90; query-replace-regexp undo feature missing quote the regexps Date: Mon, 19 Aug 2019 17:16:55 +0200 Message-ID: <87d0h1kwwo.fsf@calancha-pc.dy.bbexcite.jp> References: <87h86elgdr.fsf@calancha-pc.dy.bbexcite.jp> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="2429"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 37073@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 19 17:19:41 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hzjRd-0000UX-84 for geb-bug-gnu-emacs@m.gmane.org; Mon, 19 Aug 2019 17:19:41 +0200 Original-Received: from localhost ([::1]:54274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzjRb-0003nv-69 for geb-bug-gnu-emacs@m.gmane.org; Mon, 19 Aug 2019 11:19:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53071) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzjQ3-0002Zy-U4 for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2019 11:18:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzjQ2-0002bl-FG for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2019 11:18:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51605) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hzjQ2-0002ba-A3 for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2019 11:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hzjQ2-0001ZL-4Z for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2019 11:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Aug 2019 15:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37073 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 37073-submit@debbugs.gnu.org id=B37073.15662278295970 (code B ref 37073); Mon, 19 Aug 2019 15:18:02 +0000 Original-Received: (at 37073) by debbugs.gnu.org; 19 Aug 2019 15:17:09 +0000 Original-Received: from localhost ([127.0.0.1]:60426 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzjPB-0001YD-Bi for submit@debbugs.gnu.org; Mon, 19 Aug 2019 11:17:09 -0400 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:33083) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzjP8-0001Xm-Uq for 37073@debbugs.gnu.org; Mon, 19 Aug 2019 11:17:08 -0400 Original-Received: by mail-wr1-f41.google.com with SMTP id u16so9133102wrr.0 for <37073@debbugs.gnu.org>; Mon, 19 Aug 2019 08:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:in-reply-to:message-id:mime-version; bh=/mNqZTRcRZdVNiNirbwGkFKyO2ZdqFvh2lVzFUbTM8o=; b=pNoJjTvAfhAOfKnpDzzN8k+g2VO7ZQjpOXvqHkFWgxmfNXg04RLEuDcZsokEH0aTM3 52IEbSQXvpFwtSWtJUNiJbK6D40/NBTdXjxtddgnaxI27owyt9djQjIuEnXF5BJYUW/v Okpg3Mka6UmX1JTbgJ4oKTKZrRvFwIPB8z3BtOT7P+g5mSEIoHlKZTMhwg73ArwqcsAD eOlbW5AIGvJSUQLPOMzM+hvBYuiQJFCyhgu1ZPOOQ2rHB1IFbSqCAnkcy75JUsgGhwv2 swW/xOQ5MESh5wbrjTCIYyFgXEFvoBlOpCqcy09mpTDHuPH4XDF1eiAO1R2D7jo86ZzS 6o7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:in-reply-to:message-id :mime-version; bh=/mNqZTRcRZdVNiNirbwGkFKyO2ZdqFvh2lVzFUbTM8o=; b=M8cn/v9SrigQvsqzndaUBbhSimH22xfxIGi9qPKlkhiyejhGughHrSERlk03bWwlEK mQwX1YWhw3mcGp0pThxSnb69Z0IAfu+XD5dSws4UwWyYPM0YZEoA9BQ8BW/dtKZcM0WB fLQXCnUbXUkgLQUH0R2KZCOAsUDpzrP3X+GvYEz/ey+me6YhdTGF58RoFxla7H0sAjSF GjV2iYCT1mN1pZ8yZ6EceAUVQnGwf4mqBqKF50gdFOJi9yqqzaBkhLb3JO6ttmMPgqbG NIuYrYhhhrdrpEos8pXL073Uv2w4WrAMUOwgkXSGB8VK8MpR3kcbEWt5XjhhDutdJlBs m3iQ== X-Gm-Message-State: APjAAAWvbGMZfRE20Ygx5TfyVPn0MoDQozDy6JRPJdAFqafA5P8LyCm7 /QR3W2wZ/QYmAa80JK09SYE= X-Google-Smtp-Source: APXvYqxKKCIvxp+AWXmlOSuvkDz5KGLqozMtuM5dK3hTD7XCom7zYcJc9jZu79crRysSUvuPKljI4Q== X-Received: by 2002:adf:f008:: with SMTP id j8mr12512170wro.129.1566227821027; Mon, 19 Aug 2019 08:17:01 -0700 (PDT) Original-Received: from calancha-pc.dy.bbexcite.jp ([2a02:8308:70c5:4d00:a2fc:1435:82df:8682]) by smtp.gmail.com with ESMTPSA id g197sm10744490wme.30.2019.08.19.08.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 08:17:00 -0700 (PDT) In-Reply-To: Juri Linkov's message of "Mon\, 19 Aug 2019 00\:06\:20 +0300 \(18 hours\, 3 minutes\, 15 seconds ago\)" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:165383 Archived-At: >Thanks. Are there other looking-at/looking-back occurrences >in perform-replace that are looking at non-regexp strings? Yes, there is another one affecting the same feature (see updated patch at the end). >This looks good, but please ask Eli about pushing it to emacs-26 branch. >Recently we fixed another problem exactly in the same place, >but pushed the fix to the master. I see. Added Eli as CC. --8<-----------------------------cut here---------------start------------->8--- commit 6e58c32caaf34f914b64a6dbc976bc1e62c12d90 Author: Tino Calancha Date: Mon Aug 19 17:06:02 2019 +0200 Fix query-replace-regexp undo feature Ensure that non-regexp strings used with `looking-at' are quoted. * lisp/replace.el (perform-replace): Quote regexp (Bug#37073). * test/lisp/replace-tests.el (replace-tests-perform-replace-regexp-flag): New variable. (replace-tests-with-undo): Use it. (query-replace-undo-bug37073): Add tests. diff --git a/lisp/replace.el b/lisp/replace.el index 08feb8eae7..0ddebb1270 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2614,7 +2614,8 @@ perform-replace (setq real-match-data (save-excursion (goto-char (match-beginning 0)) - (looking-at search-string) + ;; We must quote the string (Bug#37073) + (looking-at (regexp-quote search-string)) (match-data t (nth 2 elt))) noedit (replace-match-maybe-edit @@ -2624,7 +2625,9 @@ perform-replace real-match-data (save-excursion (goto-char (match-beginning 0)) - (looking-at next-replacement) + (if regexp-flag + (looking-at next-replacement) + (looking-at (regexp-quote next-replacement))) (match-data t (nth 2 elt)))) ;; Set replaced nil to keep in loop (when (eq def 'undo-all) diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index cd30633e37..cd08a522e3 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -365,6 +365,9 @@ replace-occur-test-create (defvar replace-tests-bind-read-string nil "A string to bind `read-string' and avoid the prompt.") +(defvar replace-tests-perform-replace-regexp-flag t + "Value for regexp-flag argument passed to `perform-replace' in undo tests.") + (defmacro replace-tests-with-undo (input from to char-nums def-chr &rest body) "Helper to test `query-replace' undo feature. INPUT is a string to insert in a temporary buffer. @@ -412,7 +415,7 @@ replace-tests-with-undo (if replace-tests-bind-read-string (lambda (&rest args) replace-tests-bind-read-string) (symbol-function 'read-string)))) - (perform-replace ,from ,to t t nil)) + (perform-replace ,from ,to t replace-tests-perform-replace-regexp-flag nil)) ,@body)))) (defun replace-tests--query-replace-undo (&optional comma) @@ -454,5 +457,26 @@ replace-tests--query-replace-undo input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q (string= input (buffer-string)))))) +(ert-deftest query-replace-undo-bug37073 () + "Test for https://debbugs.gnu.org/37073 ." + (let ((input "theorem 1\ntheorem 2\ntheorem 3")) + (should + (replace-tests-with-undo + input "theorem \\([0-9]+\\)" + "theorem \\\\ref{theo_\\1}" + ((?\s . (1 2)) (?U . (3))) + ?q + (string= input (buffer-string))))) + ;; Now run a test with regexp-flag arg in `perform-replace' set to nil + (let ((input " ^theorem$ 1\n ^theorem$ 2\n ^theorem$ 3") + (replace-tests-perform-replace-regexp-flag nil) + (expected " theo 1\n ^theorem$ 2\n ^theorem$ 3")) + (should + (replace-tests-with-undo + input "^theorem$" + "theo" + ((?\s . (1 2 4)) (?U . (3))) + ?q + (string= expected (buffer-string)))))) ;;; replace-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.2.90 (build 29, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-08-19 built Repository revision: 876a0c65c4f8a28dc2fbd4d2044321d5a8c48b1a