#9402: Whitespace validates in any field that is required -------------------------------+-------------------------------------------- Reporter: hdevries | Owner: nobody Status: new | Milestone: post-1.0 Component: Core framework | Version: SVN Keywords: whitespace fields | Stage: Unreviewed Has_patch: 0 | -------------------------------+-------------------------------------------- How to reproduce: Create a form with a !CharField that has required=True .
Put whitespace into the field ( for example 4 spaces ). Submit the form. It will validate as is_valid(). The problem lies in fields.py at line 111 ( django trunk ): {{{ def clean(self, value): """ Validates the given value and returns its "cleaned" value as an appropriate Python object. Raises ValidationError for any errors. """ if self.required and value in EMPTY_VALUES: raise ValidationError(self.error_messages['required']) return value }}} At line 46 is the following: {{{ # These values, if given to to_python(), will trigger the self.required check. EMPTY_VALUES = (None, '') }}} Problem is that any amount of whitespace will get through this check. I don't know how you guys think about this ( I mean, whitespace is data ;-) ), but filling in whitespace has pretty much the same effect as filling in nothing. Proposed fix: {{{ if self.required and value.rstrip() in EMPTY_VALUES: }}} I know I should do this with a patch etc. but I don't know how to do this. I hope this is sufficient. Thanks in advance, Hdevries. -- Ticket URL: <http://code.djangoproject.com/ticket/9402> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---