Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
39ece9be
Commit
39ece9be
authored
Jun 24, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support allow_blank=False with trim_whitespace=True.
parent
d5609979
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletions
+8
-1
rest_framework/fields.py
+1
-1
tests/test_fields.py
+7
-0
No files found.
rest_framework/fields.py
View file @
39ece9be
...
@@ -580,7 +580,7 @@ class CharField(Field):
...
@@ -580,7 +580,7 @@ class CharField(Field):
# Test for the empty string here so that it does not get validated,
# Test for the empty string here so that it does not get validated,
# and so that subclasses do not need to handle it explicitly
# and so that subclasses do not need to handle it explicitly
# inside the `to_internal_value()` method.
# inside the `to_internal_value()` method.
if
data
==
''
:
if
data
==
''
or
(
self
.
trim_whitespace
and
six
.
text_type
(
data
)
.
strip
()
==
''
)
:
if
not
self
.
allow_blank
:
if
not
self
.
allow_blank
:
self
.
fail
(
'blank'
)
self
.
fail
(
'blank'
)
return
''
return
''
...
...
tests/test_fields.py
View file @
39ece9be
...
@@ -461,6 +461,13 @@ class TestCharField(FieldValues):
...
@@ -461,6 +461,13 @@ class TestCharField(FieldValues):
field
=
serializers
.
CharField
(
trim_whitespace
=
False
)
field
=
serializers
.
CharField
(
trim_whitespace
=
False
)
assert
field
.
to_internal_value
(
' abc '
)
==
' abc '
assert
field
.
to_internal_value
(
' abc '
)
==
' abc '
def
test_disallow_blank_with_trim_whitespace
(
self
):
field
=
serializers
.
CharField
(
allow_blank
=
False
,
trim_whitespace
=
True
)
with
pytest
.
raises
(
serializers
.
ValidationError
)
as
exc_info
:
field
.
run_validation
(
' '
)
assert
exc_info
.
value
.
detail
==
[
'This field may not be blank.'
]
class
TestEmailField
(
FieldValues
):
class
TestEmailField
(
FieldValues
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment