Fix spaces being stripped from password #3932
Open
+25
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of changes
AI?
AI generated PRs may be accepted, but only if @willmcgugan has responded on an issue or discussion.
Checklist
Description
Fixes #3931
This PR changes
prompt.PromptBase.process_response(...)to only callstr.strip()whenpasswordis false.Passwords could start or end with a space so I suggest not stripping them. For retro-compatibility, it seems preferable to keep the original behavior unless
PromptBase.passwordis explicitly set toTrue.This PR also adds a test to check a password input ending with a space. I resorted to monkeypatching because
console.Console.input(password=True)usesgetpass.getpass(...)which is good but has strong opinions about reading from anything else but a terminal.As a bonus note, the
streamkeyword argument ofgetpass(...)is a file-like object for printing the password prompt, not to read the password from. So it would appear thestreamargument is being used incorrectly here:rich/rich/console.py
Lines 2157 to 2165 in 53757bc
As mentioned, there is no easy way to support using
getpass(...)from anything other than standard input, so perhaps simply callgetpass("")and mark thepasswordandstreamkwargs ofConsole.input(...)mutually exclusive? But that would be outside the scope of this PR.