Subject: bug#59956: 29.0.60: Failure when completing arguments in Eshell after variable interpolation

From: Gregory Heytings <[email-masked]>
Date: Mon, 12 Dec 2022 22:21:03 +0000

>> Starting from "emacs -Q -f -eshell", type "echo $exec-path " (note the 
>> trailing space), and then hit TAB. The result is this error:
>>
>>    pcomplete-match: Wrong type argument: stringp, ("/usr/bin" ...)
>>
>> This is a regression from Emacs 28, and it looks like it's due to 
>> 'pcomplete-here-using-help' assuming that all the pcomplete args are 
>> strings. However, 'exec-path' is a list (and Eshell reports it this way 
>> to pcomplete), so the completion fails. I think all that's necessary is 
>> checking that the pcomplete args are strings in 
>> 'pcomplete-here-using-help', but I know next to nothing about 
>> pcomplete...
>
> Adding Stefan, who should know more about pcomplete.
>
> Stefan, any suggestions?
>

I'm still not Stefan, but this bug is fixed by the attached patch.
From 60416d39cda3ebf336bdb77487d3b7d8d429f1b6 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Mon, 12 Dec 2022 22:16:18 +0000
Subject: [PATCH] Check that arguments are strings in pcomplete-here-using-help

* lisp/pcomplete.el (pcomplete-here-using-help): Check that
pcomplete-args are strings before applying string operations on
them.  Fixes bug#59956 and bug#60021.
---
 lisp/pcomplete.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el
index 4e3a88bbda8..c63c490bcaa 100644
--- a/lisp/pcomplete.el
+++ b/lisp/pcomplete.el
@@ -1449,12 +1449,18 @@ pcomplete-here-using-help
 The switches are obtained by calling `pcomplete-from-help' with
 COMMAND and ARGS as arguments."
   (while (cond
-          ((string= "--" (pcomplete-arg 1))
+          ((let ((arg (pcomplete-arg 1)))
+             (if (stringp arg)
+                 (string= "--" arg)))
            (while (pcomplete-here (pcomplete-entries))))
-          ((pcomplete-match "\\`--[^=]+=\\(.*\\)" 0)
+          ((let ((arg (pcomplete-arg 0)))
+             (if (stringp arg)
+                 (pcomplete-match "\\`--[^=]+=\\(.*\\)" 0)))
            (pcomplete-here (pcomplete-entries)
                            (pcomplete-match-string 1 0)))
-          ((string-prefix-p "-" (pcomplete-arg 0))
+          ((let ((arg (pcomplete-arg 0)))
+             (if (stringp arg)
+                 (string-prefix-p "-" arg)))
            (pcomplete-here (apply #'pcomplete-from-help command args)))
           (t (pcomplete-here* (pcomplete-entries))))))
 
-- 
2.35.1