Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

click.prompt(type=int, hide_input=True) outputs rejected input #1460

Closed
altendky opened this issue Jan 28, 2020 · 4 comments · Fixed by #1587
Closed

click.prompt(type=int, hide_input=True) outputs rejected input #1460

altendky opened this issue Jan 28, 2020 · 4 comments · Fixed by #1587

Comments

@altendky
Copy link
Contributor

Despite asking click.prompt() to hide input it will still outputs the input if it rejects it. I get the same behavior for 7.0 from PyPI, 7.x from Git, and master from Git.

altendky@p1:~$ venv/bin/python -c 'import click; click.prompt("prompt", type=int, hide_input=True)'
prompt: 
Error: wait...  i get to see this? is not a valid integer
prompt:

If you specify a type (let's say you are inputting a numeric pin) then the same can happen with click.password_option().

import click


@click.command()
@click.password_option(type=int)
def cli(password):
    pass


cli()
altendky@p1:~$ venv/bin/python x.py
Password: 
Error: lkjsaf is not a valid integer
Password:

The workaround for click.prompt() anyways I guess is to not specify a type and to implement the rejection manually.

If there is agreement that this is an issue that should be fixed then I can try to put together a PR for it.

@davidism
Copy link
Member

Did you have a fix in mind?

One option is to wrap the call to type in try/except Exception and output a generic "The value you entered was invalid." if hide_input is true.

@altendky
Copy link
Contributor Author

No, I had not looked at the code or thought about it beyond just making sure the input does not end up in the output. Sounds like you think the concern is reasonable so I can try to find time to see if I can make a reasonable solution.

@altendky
Copy link
Contributor Author

When I find time, should I target 7.x or master?

@davidism
Copy link
Member

davidism commented Jan 29, 2020

7.x is fine target master now

@davidism davidism added this to the 8.0.0 milestone Jun 11, 2020
csr added a commit to csr/click that referenced this issue Jun 11, 2020
Fixed an error that would display prompt input in the error message even if hide_input was enabled
csr added a commit to csr/click that referenced this issue Jun 15, 2020
Fixed an error that would display prompt input in the error message even if hide_input was enabled
csr added a commit to csr/click that referenced this issue Jun 19, 2020
Update termui.py

Minor formatting fix

Fixes pallets#1460: hide prompt input if hide_input is enabled
csr added a commit to csr/click that referenced this issue Jun 19, 2020
csr added a commit to csr/click that referenced this issue Jun 19, 2020
davidism added a commit that referenced this issue Jun 24, 2020
Fix #1460: hide prompt input if hide_input is enabled
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants