attachments: fix #67

This commit is contained in:
Darks 2020-08-02 15:03:08 +02:00
parent 03c577316f
commit a83cef5970
Signed by: Darks
GPG Key ID: F61F10FA138E797C
2 changed files with 11 additions and 1 deletions

View File

@ -8,7 +8,7 @@ class CommentForm(FlaskForm):
message = TextAreaField('Message', validators=[DataRequired()])
attachments = MultipleFileField('Pièces-jointes',
validators=[vd.file.optional, vd.file.count, vd.file.extension,
vd.file.size])
vd.file.size, vd.file.namelength])
submit = SubmitField('Commenter')
preview = SubmitField('Prévisualiser')

View File

@ -49,3 +49,13 @@ def size(form, files):
else:
if size > 500e3: # 500 ko per comment for a guest
raise ValidationError("Fichiers trop lourds (max 500ko)")
def namelength(form, files):
errors = []
for f in files.data:
name = secure_filename(f.filename)
if len(name) > 64:
errors.append(f.filename)
if len(errors) > 0:
raise ValidationError(f"Noms trop longs, 64 caractères max " \
f"({', '.join(errors)})")