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

Sanitization for click inputs #457

Closed
Tylerlhess opened this issue Nov 18, 2015 · 6 comments · Fixed by #1785
Closed

Sanitization for click inputs #457

Tylerlhess opened this issue Nov 18, 2015 · 6 comments · Fixed by #1785
Assignees
Labels
f:prompt feature: prompt for input
Milestone

Comments

@Tylerlhess
Copy link

I would like to see some method of easy sanitation after an input. I guess I could define a type and require that type for the input but that seems a little extravagant if I want to make sure that say a field entered is a valid email address during input or to strip out spaces automatically. I know I can do this in the code but it should be possible inside prompt.

@mitsuhiko
Copy link
Contributor

Can you not use our callback system for this?

@mitsuhiko
Copy link
Contributor

Oh I see. We might only invoke the type conversion but not the callbacks for prompts currently. I wonder if that can be changed though.

@piroux
Copy link

piroux commented Nov 19, 2015

It would be a good feature indeed.

@Tylerlhess
Copy link
Author

Yeah in the code I wrote I ended up just calling strip to sanitize it somewhat and prevent spaces at the beginning and the end but that does not actually validate the data. It does fix the issue I had of people using copy and paste and grabbing a space but not the underlying problem of allowing a complete input sanitization check.

@davidism
Copy link
Member

davidism commented Feb 15, 2021

Parameter.callback is already called for the result of prompt (or any other parameter source), but it's called after prompt returns, not inside it. So while it's possible to perform extra processing, if that processing raises a click.UsageError it exits instead of prompting again.

I'm not sure if this was always the case or if it was due to recent refactors to the type processing pipeline. I think we can extend that refactoring a bit further though to address this issue. prompt is passed self.process_value, which only does type conversion. However, handle_parse_result calls full_process_value (which calls process_value) then applies the callback separately. There's no reason to have that separate anymore, and along with that there's no reason to have both process_value and full_process_value.

  1. Inline Parameter.process_value into Parameter.full_process_value.
  2. Rename full_process_value to process_value.
  3. Move the if self.callback: block from Parameter.handle_parse_result to the bottom of process_value.

@Saif807380
Copy link
Contributor

I'd like to work on this.

@davidism davidism added this to the 8.0.0 milestone Feb 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f:prompt feature: prompt for input
Projects
None yet
6 participants