1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #9893 -- Validated the length of file names

after the full file name is generated by the storage class.

Thanks Refefer for the report, carsongee for the patch, and
everyone else involved in the discussion.
This commit is contained in:
Aymeric Augustin
2012-05-17 16:02:05 +02:00
parent 82a76ef67d
commit dcd4383107
2 changed files with 33 additions and 0 deletions

View File

@@ -365,3 +365,15 @@ class FileFieldTests(unittest.TestCase):
field = d._meta.get_field('myfile')
field.save_form_data(d, 'else.txt')
self.assertEqual(d.myfile, 'else.txt')
def test_max_length(self):
"""
Test that FileField validates the length of the generated file name
that will be stored in the database. Regression for #9893.
"""
# upload_to = 'unused', so file names are saved as 'unused/xxxxx'.
# max_length = 100, so names longer than 93 characters are rejected.
Document(myfile=93 * 'x').full_clean()
with self.assertRaises(ValidationError):
Document(myfile=94 * 'x').full_clean()