GeezerVison is showing github.com — Sanitization for click inputs · Issue #457 · pallets/click
Sanitization for click inputs #457
Labels
promptInteractive input and confirmation Description
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.
Activity
mitsuhiko commented on Nov 18, 2015
Can you not use our callback system for this?
mitsuhiko commented on Nov 18, 2015
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 commented on Nov 19, 2015
It would be a good feature indeed.
Tylerlhess commented on Nov 23, 2015
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 commented on 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.
- Inline
Parameter.process_value into Parameter.full_process_value.
- Rename
full_process_value to process_value.
- Move the
if self.callback: block from Parameter.handle_parse_result to the bottom of process_value.
Saif807380 commented on Feb 23, 2021
I'd like to work on this.
locked as resolved and limited conversation to collaborators
on Mar 11, 2021
Metadata
Metadata
promptInteractive input and confirmation Development
No branches or pull requestsIssue actions