From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#46271: 28.0.50; [PATCH] Properly quote group names for gnus-search Date: Sun, 07 Feb 2021 14:26:39 -0800 Message-ID: <87o8gvjyzk.fsf@ericabrahamsen.net> References: <877dnpcm5t.fsf@disroot.org> <875z38zrg4.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32322"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: jflack@disroot.org To: 46271@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 07 23:27:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8sWY-0008FP-NR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 23:27:22 +0100 Original-Received: from localhost ([::1]:34480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8sWX-0002Jb-Q6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 17:27:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8sWE-0002Ie-DA for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 17:27:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8sWE-0004KY-5R for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 17:27:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l8sWD-0001OD-Uv for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 17:27:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Feb 2021 22:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46271 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46271-submit@debbugs.gnu.org id=B46271.16127368105322 (code B ref 46271); Sun, 07 Feb 2021 22:27:01 +0000 Original-Received: (at 46271) by debbugs.gnu.org; 7 Feb 2021 22:26:50 +0000 Original-Received: from localhost ([127.0.0.1]:49150 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8sW1-0001Nm-Lb for submit@debbugs.gnu.org; Sun, 07 Feb 2021 17:26:49 -0500 Original-Received: from ericabrahamsen.net ([52.70.2.18]:35152 helo=mail.ericabrahamsen.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8sVz-0001NZ-Cp for 46271@debbugs.gnu.org; Sun, 07 Feb 2021 17:26:48 -0500 Original-Received: from localhost (c-73-254-86-141.hsd1.wa.comcast.net [73.254.86.141]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 4D395FA206; Sun, 7 Feb 2021 22:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1612736801; bh=7Q5gfiILM/v+hh2t+7ryLg8Q509j5PYn843jWxEUqCc=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=cTZGEP3V7jgGZYwdYhNXkMUCnWEdaTWFSlKWduP3CcMhtGIPVgjQtwXnlwpaotqYz 1mlThYA0Fn601kQVlHUK2KhJC3gFYqpo4/wRY2g729Ct/PXsoaENhh3O0s1NqLWUar 4ncYjOGwkcsfYDjc31NjCAKK1pqEbTnDoy0MkBlk= In-Reply-To: <875z38zrg4.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Wed, 03 Feb 2021 15:01:31 -0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199581 Archived-At: Eric Abrahamsen writes: > jflack--- via "Bug reports for GNU Emacs, the Swiss army knife of text > editors" writes: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA512 >> >> - --=-=-= >> Content-Type: text/plain >> Content-Transfer-Encoding: quoted-printable >> >> >> The new gnus-search-indexed-parse-output doesn't properly quote group >> names before using them as regexes meaning a group name containing >> meta-characters (other than . or \ because of the current replacement) >> won't be properly matched in the search results later. >> >> I have attached a diff that fixes this by first quoting the group name >> before performing the replacement; which is now constructed with RX >> to save \\ soup. >> >> =2D-=20 >> Thanks, >> Jai >> >> - --=-=-= >> Content-Type: text/x-diff >> Content-Disposition: attachment; filename=gnus-search-regex.diff >> Content-Transfer-Encoding: quoted-printable >> >> diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el >> index 44f43b073c..54603d8792 100644 >> =2D-- a/lisp/gnus/gnus-search.el >> +++ b/lisp/gnus/gnus-search.el >> @@ -82,6 +82,7 @@ >> (require 'gnus-util) >> (require 'eieio) >> (eval-when-compile (require 'cl-lib)) >> +(eval-when-compile (require 'rx)) >> (autoload 'eieio-build-class-alist "eieio-opt") >> (autoload 'nnmaildir-base-name-to-article-number "nnmaildir") >> =20 >> @@ -1380,8 +1381,8 @@ gnus-search-indexed-parse-output >> (lambda (x) >> (replace-regexp-in-string >> ;; Accept any of [.\/] as path separators. >> =2D "[.\\/]" "[.\\\\/]" >> =2D (gnus-group-real-name x))) >> + (rx (or "\\." "\\\\" "/")) "[.\\\\/]" >> + (regexp-quote (gnus-group-real-name x)))) >> groups "\\|"))) >> artlist vectors article group) >> (goto-char (point-min)) > > Thanks very much for the patch! Let me do some local testing over the > next couple of days, but at first glance this looks like it will do the > trick. Finally getting to this... This doesn't quite do what it intends to do, as the `replace-regexp-in-string' interferes with the `regexp-quote'. To wit: (let ((group-name "mail+")) (replace-regexp-in-string "[.\\/]" "[.\\\\/]" (regexp-quote (gnus-group-real-name group-name)))) -> "mail[.\\/]+" But what we wanted was: "mail\\+" So I think it has to get messier: (let ((groups '("mail+" "gnus.gener+al" "archive.2007.10"))) (mapconcat #'identity (mapcar (lambda (group-name) (mapconcat #'regexp-quote (split-string (gnus-group-real-name group-name) "[.\\/]") "[.\\\\/]")) groups) "\\|")) -> "mail\\+\\|gnus[.\\\\/]gener\\+al\\|archive[.\\\\/]2007[.\\\\/]10" This looks right to me. WDYT? Also, I'd prefer not to use rx in this case, simply because this: "[.\\/]" turns into this: (rx (or "\\." "\\\\" "/")) Which seems like a loss of readability, though in general I think rx is a very good idea. Thanks again for the report! Eric