[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#46271: 28.0.50; [PATCH] Properly quote group names for gnus-search
From: |
Eric Abrahamsen |
Subject: |
bug#46271: 28.0.50; [PATCH] Properly quote group names for gnus-search |
Date: |
Sun, 07 Feb 2021 14:26:39 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> jflack--- via "Bug reports for GNU Emacs, the Swiss army knife of text
> editors" <bug-gnu-emacs@gnu.org> 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