Strip fields' values consistently
Currently, some fields strips values during validation and some do not. The state does not even clearly represents whether whitespace is valid part of field's value.
Field | Strips | Should strip
|
CharField | no | no
|
IntegerField | yes | yes
|
FloatField | yes | yes
|
DecimalField | yes | yes
|
BaseTemporalField | yes | yes
|
RegexField | no | no
|
EmailField | yes | yes
|
URLField | no | yes
|
BooleanField | no | ?
|
NullBooleanField | no | ?
|
IPAddressField | no | yes
|
GenericIPAddressField | no | yes
|
SlugField | no | yes
|
Comments:
- Spaces are not allowed in URLField, IPAddressField, GenericIPAddressField and SlugField
- Fairly unclear are boolean fields. IMHO if value to validate is string of whitespace characters, it should validate to None/False as when represented by TextInput user will see empty field.
I have not check localised form fields but I expect more fields that can be safely trimmed.
Maybe a good long-term solution would be list of filters (like validators) which would perform transformation to python object.
Attachments
(1)
- ticket_18761.diff
(1.3 KB
) - added by Lebedev Ilya 12 years ago.
- Added stripping for URLField, IPAddressField, GenericIPAddressField, SlugField. I have two questions: is it all that should be done? Why no tests are required?
Download all attachments as:
.zip
Change History
(11)
Easy pickings: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to Lebedev Ilya
|
Owner: |
changed from Lebedev Ilya to Sasha Romijn
|
Owner: |
Sasha Romijn removed
|
Status: |
assigned → new
|
Owner: |
set to Deni Bertovic
|
Status: |
new → assigned
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
I've actually gotten this as a feature request on projects I've worked on in the wild... I assumed that django just wasn't stripping any field values of whitespace. But it is, either implicitly or explicity. It would be good to be consistent. So it would make sense (to me) to strip whitespace on !URLField, !IPAddressField, !GenericIPAddressField, and SlugField - maybe leave the BooleanFields for later/never, since the case isn't clear.