Subject: bug#64795: 30.0.50; manual-entry [(1) fails

From: Eli Zaretskii <[email-masked]>
Date: Sun, 23 Jul 2023 22:23:48 +0300

> From: Michael Heerdegen <[email-masked]>
> Date: Sun, 23 Jul 2023 02:58:59 +0200
> 
> In Gnu/Linux there is a binary named "[" in /usr/bin/, and it has a man
> page I can read in a terminal using "man '[(1)'".
> 
> Requesting the man page in Emacs using `man' is broken, however:
> 
>   M-x manual-entry RET [ TAB
> 
> echoes "[No match]" - this is the first problem (the failing
> completion).
> 
> C-g, let's try differently:
> 
>   M-x manual-entry RET TAB [ TAB
> 
> (that's the same as before but additionally requesting all candidates
> before writing in the minibuffer) suddenly completes to "[(1)" as
> expected.  But when confirming with RET the man buffer only has these
> contents:
> 
> | /bin/sh: 1: Syntax error: "(" unexpected
> |
> | process exited abnormally with code 2
> 
> That's the second problem.

Does the patch below give good results?

diff --git a/lisp/man.el b/lisp/man.el
index 479bf9f9a3c..bbcbe5d1525 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -315,7 +315,7 @@ Man-cooked-hook
   :type 'hook
   :group 'man)
 
-(defvar Man-name-regexp "[-[:alnum:]_+][-[:alnum:]_.:+]*"
+(defvar Man-name-regexp "[-[:alnum:]_+[][-[:alnum:]_.:+]*"
   "Regular expression describing the name of a manpage (without section).")
 
 (defvar Man-section-regexp "[0-9][a-zA-Z0-9+]*\\|[LNln]"
@@ -937,7 +937,7 @@ Man-completion-table
                          "-k" (concat (when (or Man-man-k-use-anchor
                                                 (string-equal prefix ""))
                                         "^")
-                                      prefix))))
+                                      (shell-quote-argument prefix)))))
               (setq table (Man-parse-man-k)))))
 	;; Cache the table for later reuse.
         (when table