Subject: Re: bug#76551: 31.0.50; Missing space in minibuffer `sudo' password

From: Rudolf Adamkovič <[email-masked]>
Date: Fri, 28 Feb 2025 15:11:25 +0100

Visuwesh <[email-masked]> writes:

> The prompt is from `sudo'.  comint-watch-for-password-prompt, which is
> in comint-output-filter-functions, turns the password prompt in
> *testing* buffer to read-passwd call.

Thank you for locating the problem.

Eli, how about the attached patch?

Rudy
>From 2a10fdee87e75f2eca1005ef186044adbd854ebb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <[email-masked]>
Date: Fri, 28 Feb 2025 14:54:14 +0100
Subject: [PATCH] Make sure Comint minibuffer password prompts end with space

* lisp/comint.el (comint-watch-for-password-prompt): Add a trailing
space character to the minibuffer password prompt, if it does not
contain one already, per the minibuffer UI conventions.

Bug#76604
---
 lisp/comint.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index c1028bc93dc..f0305e4de3c 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2601,8 +2601,14 @@ comint-watch-for-password-prompt
         prompt)
     (when (let ((case-fold-search t))
             (string-match comint-password-prompt-regexp string))
-      (setq prompt (string-trim (match-string 0 string)
-                                "[ \n\r\t\v\f\b\a]+" "\n+"))
+      (setq prompt
+            (let ((content (string-trim (match-string 0 string)
+                                        "[ \n\r\t\v\f\b\a]+" "\n+"))
+                  (suffix " "))
+              (concat content
+                      (and (not (string-empty-p content))
+                           (not (string-suffix-p suffix content))
+                           suffix))))
       ;; Use `run-at-time' in order not to pause execution of the
       ;; process filter with a minibuffer
       (run-at-time
-- 
2.39.5 (Apple Git-154)

-- 
"One can begin to reason only when a clear picture has been formed in
the imagination."
--- Walter Warwick Sawyer, Mathematician's Delight, 1943

Rudolf Adamkovič <[email-masked]> [he/him]
http://adamkovic.org