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
284f9faa
Commit
284f9faa
authored
Sep 11, 2015
by
Steven Loria
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly handle [] and {} as invalid inputs to BooleanField
parent
a67eed14
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
rest_framework/fields.py
+7
-4
tests/test_fields.py
+12
-0
No files found.
rest_framework/fields.py
View file @
284f9faa
...
@@ -608,10 +608,13 @@ class BooleanField(Field):
...
@@ -608,10 +608,13 @@ class BooleanField(Field):
super
(
BooleanField
,
self
)
.
__init__
(
**
kwargs
)
super
(
BooleanField
,
self
)
.
__init__
(
**
kwargs
)
def
to_internal_value
(
self
,
data
):
def
to_internal_value
(
self
,
data
):
if
data
in
self
.
TRUE_VALUES
:
try
:
return
True
if
data
in
self
.
TRUE_VALUES
:
elif
data
in
self
.
FALSE_VALUES
:
return
True
return
False
elif
data
in
self
.
FALSE_VALUES
:
return
False
except
TypeError
:
# Input is an unhashable type
pass
self
.
fail
(
'invalid'
,
input
=
data
)
self
.
fail
(
'invalid'
,
input
=
data
)
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
...
...
tests/test_fields.py
View file @
284f9faa
...
@@ -466,6 +466,18 @@ class TestBooleanField(FieldValues):
...
@@ -466,6 +466,18 @@ class TestBooleanField(FieldValues):
}
}
field
=
serializers
.
BooleanField
()
field
=
serializers
.
BooleanField
()
def
test_disallow_unhashable_collection_types
(
self
):
inputs
=
(
[],
{},
)
field
=
serializers
.
BooleanField
()
for
input_value
in
inputs
:
with
pytest
.
raises
(
serializers
.
ValidationError
)
as
exc_info
:
field
.
run_validation
(
input_value
)
expected
=
[
'"{0}" is not a valid boolean.'
.
format
(
input_value
)]
assert
exc_info
.
value
.
detail
==
expected
class
TestNullBooleanField
(
FieldValues
):
class
TestNullBooleanField
(
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