mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
[5.1.x] Fixed #35483 -- Added NUL (0x00) character validation to ModelChoiceFields.
Applied the ProhibitNullCharactersValidator to ModelChoiceField and ModelMultipleChoiceField.
Co-authored-by: Viktor Paripás <viktor.paripas@gmail.com>
Co-authored-by: Vasyl Dizhak <vasyl@dizhak.com>
Co-authored-by: Arthur Vasconcelos <vasconcelos.arthur@gmail.com>
Backport of 38ad710aba from main.
This commit is contained in:
committed by
Sarah Boyce
parent
a0f6835f72
commit
b8983dcf57
@@ -7,7 +7,7 @@ from django.forms.widgets import CheckboxSelectMultiple
|
||||
from django.template import Context, Template
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Article, Author, Book, Category, Writer
|
||||
from .models import Article, Author, Book, Category, ExplicitPK, Writer
|
||||
|
||||
|
||||
class ModelChoiceFieldTests(TestCase):
|
||||
@@ -79,6 +79,12 @@ class ModelChoiceFieldTests(TestCase):
|
||||
self.assertEqual(f.clean(self.c1.slug), self.c1)
|
||||
self.assertEqual(f.clean(self.c1), self.c1)
|
||||
|
||||
def test_model_choice_null_characters(self):
|
||||
f = forms.ModelChoiceField(queryset=ExplicitPK.objects.all())
|
||||
msg = "Null characters are not allowed."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
f.clean("\x00something")
|
||||
|
||||
def test_choices(self):
|
||||
f = forms.ModelChoiceField(
|
||||
Category.objects.filter(pk=self.c1.id), required=False
|
||||
|
||||
Reference in New Issue
Block a user