mirror of
https://github.com/django/django.git
synced 2025-11-13 17:09:28 +00:00
Fixed #24531 -- Improved CommaSeparatedIntegerField validation.
`','`, `'1,,1'`, `',1'` etc. are no longer considered as valid comma-separated integer lists.
This commit is contained in:
parent
f4cc0c40a8
commit
3e64f3d0fc
5 changed files with 49 additions and 17 deletions
|
|
@ -254,11 +254,14 @@ def ip_address_validators(protocol, unpack_ipv4):
|
|||
raise ValueError("The protocol '%s' is unknown. Supported: %s"
|
||||
% (protocol, list(ip_address_validator_map)))
|
||||
|
||||
comma_separated_int_list_re = re.compile('^[\d,]+$')
|
||||
validate_comma_separated_integer_list = RegexValidator(
|
||||
comma_separated_int_list_re,
|
||||
_('Enter only digits separated by commas.'),
|
||||
'invalid'
|
||||
|
||||
def int_list_validator(sep=',', message=None, code='invalid'):
|
||||
regexp = re.compile('^\d+(?:%s\d+)*$' % re.escape(sep))
|
||||
return RegexValidator(regexp, message=message, code=code)
|
||||
|
||||
|
||||
validate_comma_separated_integer_list = int_list_validator(
|
||||
message=_('Enter only digits separated by commas.'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue