File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -580,7 +580,7 @@ def run_validation(self, data=empty):
580
580
# Test for the empty string here so that it does not get validated,
581
581
# and so that subclasses do not need to handle it explicitly
582
582
# inside the `to_internal_value()` method.
583
- if data == '' :
583
+ if data == '' or ( self . trim_whitespace and six . text_type ( data ). strip () == '' ) :
584
584
if not self .allow_blank :
585
585
self .fail ('blank' )
586
586
return ''
Original file line number Diff line number Diff line change @@ -461,6 +461,13 @@ def test_trim_whitespace_disabled(self):
461
461
field = serializers .CharField (trim_whitespace = False )
462
462
assert field .to_internal_value (' abc ' ) == ' abc '
463
463
464
+ def test_disallow_blank_with_trim_whitespace (self ):
465
+ field = serializers .CharField (allow_blank = False , trim_whitespace = True )
466
+
467
+ with pytest .raises (serializers .ValidationError ) as exc_info :
468
+ field .run_validation (' ' )
469
+ assert exc_info .value .detail == ['This field may not be blank.' ]
470
+
464
471
465
472
class TestEmailField (FieldValues ):
466
473
"""
You can’t perform that action at this time.
0 commit comments