Commit 8dba811
committed
Return ValidationError for non-string input instead of leaking AttributeError
Validators that reach for string methods on the value -- uuid via
UUID(value) -> value.replace, email/hostname via value.count, cron via
value.strip -- raise AttributeError when given a non-string (int, float,
bool, list, dict). The validator decorator only converted (ValueError,
TypeError, UnicodeError) to ValidationError, so AttributeError escaped
uncaught: a caller passing untrusted or unknown-typed data to a validator
got a crash instead of the documented True/ValidationError result, and
inconsistently with the many validators that already return ValidationError
for wrong-typed input.
Add AttributeError to the decorator's caught set so this whole class of
validators handles non-string input uniformly.1 parent 70de324 commit 8dba811
2 files changed
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | | - | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
0 commit comments