mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Merge c23589fa3a
into d12005cf90
This commit is contained in:
commit
57ba5bc703
|
@ -806,6 +806,8 @@ class RegexField(CharField):
|
|||
|
||||
def __init__(self, regex, **kwargs):
|
||||
super(RegexField, self).__init__(**kwargs)
|
||||
if isinstance(regex, six.string_types):
|
||||
regex = re.compile(regex, re.UNICODE)
|
||||
validator = RegexValidator(regex, message=self.error_messages['invalid'])
|
||||
self.validators.append(validator)
|
||||
|
||||
|
|
|
@ -709,6 +709,20 @@ class TestiCompiledRegexField(FieldValues):
|
|||
field = serializers.RegexField(regex=re.compile('[a-z][0-9]'))
|
||||
|
||||
|
||||
class TestUnicodeRegexField(FieldValues):
|
||||
"""
|
||||
Valid and invalid values for `RegexField`.
|
||||
"""
|
||||
valid_inputs = {
|
||||
u'hello\u4f60\u597d': u'hello\u4f60\u597d'
|
||||
}
|
||||
invalid_inputs = {
|
||||
u'hello\u4f60\u597d@': ["This value does not match the required pattern."]
|
||||
}
|
||||
outputs = {}
|
||||
field = serializers.RegexField(regex='^\w*$')
|
||||
|
||||
|
||||
class TestSlugField(FieldValues):
|
||||
"""
|
||||
Valid and invalid values for `SlugField`.
|
||||
|
|
Loading…
Reference in New Issue
Block a user