mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Remove compat for ProhibitNullCharactersValidator (#7333)
This commit is contained in:
parent
fccfdd21c0
commit
aed74961ba
|
@ -19,11 +19,6 @@ except ImportError:
|
|||
RegexURLResolver as URLResolver,
|
||||
)
|
||||
|
||||
try:
|
||||
from django.core.validators import ProhibitNullCharactersValidator # noqa
|
||||
except ImportError:
|
||||
ProhibitNullCharactersValidator = None
|
||||
|
||||
|
||||
def get_original_route(urlpattern):
|
||||
"""
|
||||
|
|
|
@ -14,7 +14,8 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.core.validators import (
|
||||
EmailValidator, MaxLengthValidator, MaxValueValidator, MinLengthValidator,
|
||||
MinValueValidator, RegexValidator, URLValidator, ip_address_validators
|
||||
MinValueValidator, ProhibitNullCharactersValidator, RegexValidator,
|
||||
URLValidator, ip_address_validators
|
||||
)
|
||||
from django.forms import FilePathField as DjangoFilePathField
|
||||
from django.forms import ImageField as DjangoImageField
|
||||
|
@ -33,7 +34,6 @@ from pytz.exceptions import InvalidTimeError
|
|||
from rest_framework import (
|
||||
ISO_8601, RemovedInDRF313Warning, RemovedInDRF314Warning
|
||||
)
|
||||
from rest_framework.compat import ProhibitNullCharactersValidator
|
||||
from rest_framework.exceptions import ErrorDetail, ValidationError
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.utils import html, humanize_datetime, json, representation
|
||||
|
@ -785,9 +785,7 @@ class CharField(Field):
|
|||
self.validators.append(
|
||||
MinLengthValidator(self.min_length, message=message))
|
||||
|
||||
# ProhibitNullCharactersValidator is None on Django < 2.0
|
||||
if ProhibitNullCharactersValidator is not None:
|
||||
self.validators.append(ProhibitNullCharactersValidator())
|
||||
self.validators.append(ProhibitNullCharactersValidator())
|
||||
self.validators.append(ProhibitSurrogateCharactersValidator())
|
||||
|
||||
def run_validation(self, data=empty):
|
||||
|
|
|
@ -13,7 +13,6 @@ from django.utils.timezone import activate, deactivate, override, utc
|
|||
|
||||
import rest_framework
|
||||
from rest_framework import exceptions, serializers
|
||||
from rest_framework.compat import ProhibitNullCharactersValidator
|
||||
from rest_framework.fields import (
|
||||
BuiltinSignatureError, DjangoImageField, is_simple_callable
|
||||
)
|
||||
|
@ -747,7 +746,6 @@ class TestCharField(FieldValues):
|
|||
field.run_validation(' ')
|
||||
assert exc_info.value.detail == ['This field may not be blank.']
|
||||
|
||||
@pytest.mark.skipif(ProhibitNullCharactersValidator is None, reason="Skipped on Django < 2.0")
|
||||
def test_null_bytes(self):
|
||||
field = serializers.CharField()
|
||||
|
||||
|
@ -762,8 +760,8 @@ class TestCharField(FieldValues):
|
|||
field = serializers.CharField()
|
||||
|
||||
for code_point, expected_message in (
|
||||
(0xD800, 'Surrogate characters are not allowed: U+D800.'),
|
||||
(0xDFFF, 'Surrogate characters are not allowed: U+DFFF.'),
|
||||
(0xD800, 'Surrogate characters are not allowed: U+D800.'),
|
||||
(0xDFFF, 'Surrogate characters are not allowed: U+DFFF.'),
|
||||
):
|
||||
with pytest.raises(serializers.ValidationError) as exc_info:
|
||||
field.run_validation(chr(code_point))
|
||||
|
|
Loading…
Reference in New Issue
Block a user