Skip to content

Conversation

@ncanceill
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

AI?

  • AI was used to generate this PR

AI generated PRs may be accepted, but only if @willmcgugan has responded on an issue or discussion.

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Fixes #3931

This PR changes prompt.PromptBase.process_response(...) to only call str.strip() when password is 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.password is explicitly set to True.

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) uses getpass.getpass(...) which is good but has strong opinions about reading from anything else but a terminal.

As a bonus note, the stream keyword argument of getpass(...) is a file-like object for printing the password prompt, not to read the password from. So it would appear the stream argument is being used incorrectly here:

rich/rich/console.py

Lines 2157 to 2165 in 53757bc

stream: (TextIO, optional): Optional file to read input from (rather than stdin). Defaults to None.
Returns:
str: Text read from stdin.
"""
if prompt:
self.print(prompt, markup=markup, emoji=emoji, end="")
if password:
result = getpass("", stream=stream)

As mentioned, there is no easy way to support using getpass(...) from anything other than standard input, so perhaps simply call getpass("") and mark the password and stream kwargs of Console.input(...) mutually exclusive? But that would be outside the scope of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] spaces stripped from password

1 participant