Subject: bug#43003: 28.0.50; comint-password-prompt-regexp too restrictive

From: Stephen Berman <[email-masked]>
Date: Mon, 31 Aug 2020 14:05:48 +0200

On Mon, 31 Aug 2020 12:11:54 +0200 Robert Pluim <[email-masked]> wrote:

>>>>>> On Mon, 31 Aug 2020 11:26:10 +0200, Stephen Berman
> <[email-masked]> said:
>
>     Stephen> On Sun, 30 Aug 2020 15:41:57 +0200 Lars Ingebrigtsen
>     Stephen> <[email-masked]> wrote:
>     >> Stephen Berman <[email-masked]> writes:
>     >>
>     >>> True, I wasn't thinking about that.  Then I guess it's best to leave
>     >>> comint-password-prompt-regexp as is and I'll just change it locally.
>     >>> The problem I have with it doesn't seem to be widespread, to say the
>     >>> least.  So feel free to close the bug.
>     >>
>     >> OK; done.
>
>     Stephen> A postscript with additional datapoints: In my OP, the the system that
>     Stephen> the problem occurs on (Linux From Scratch) uses openssh 8.2p1, while the
>     Stephen> system without the problem (an older Linux From Scratch) uses openssh
>     Stephen> 7.9p1.  I've now reproduced the problem on two other GNU/Linux systems:
>     Stephen> current openSUSE Tumbleweed, which uses openssh 8.3p1 (and I see the
>     Stephen> problem here on two different machines), and openSUSE Leap 15.2, which
>     Stephen> uses openssh 8.1p1.  This supports my conjecture that the problematic
>     Stephen> carriage return in the prompt comes from openssh.  If anyone else
>     Stephen> running a system with openssh 8.{1,2,3}p1 can reproduce the problem,
>     Stephen> then perhaps a different way of handling it than changing the default
>     Stephen> value of comint-password-prompt-regexp can be found.
>
> That matches the analysis done in
>
> https://emacs.stackexchange.com/questions/60394/unable-to-push-into-github-using-magit
>
> which leads to:
>
> https://github.com/magit/magit/issues/3843
>
> TL;DR magit decided to strip the \r from the prompt received from
> openssh.

Ah, thanks for the pointer.  I'd done a web search before my first post
about this but didn't find those pages.

> We could strip control characters in comint-watch-for-password-prompt,
> but then people who've legitimately put control characters in
> comint-password-prompt-regexp will get annoyed.
>
> Perhaps just strip '\r'? (And document it, of course)
>
> diff --git a/lisp/comint.el b/lisp/comint.el
> index be0e32b9e0..74c5c7f94f 100644
> --- a/lisp/comint.el
> +++ b/lisp/comint.el
> @@ -2427,7 +2427,8 @@ comint-watch-for-password-prompt
>
>  This function could be in the list `comint-output-filter-functions'."
>    (when (let ((case-fold-search t))
> -	  (string-match comint-password-prompt-regexp string))
> +	  (string-match comint-password-prompt-regexp
> +                        (replace-regexp-in-string "\r" "" string)))
>      (when (string-match "^[ \n\r\t\v\f\b\a]+" string)
>        (setq string (replace-match "" t t string)))
>      (let ((comint--prompt-recursion-depth (1+ comint--prompt-recursion-depth)))

That works for me.  Thanks,

Steve Berman