mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Merge pull request #3348 from alphagov/no-embedded-images-in-SVG-logo-files
Do not allow to upload SVG logos with embedded raster images in them
This commit is contained in:
@@ -42,6 +42,7 @@ from app.main.validators import (
|
||||
LettersNumbersAndFullStopsOnly,
|
||||
MustContainAlphanumericCharacters,
|
||||
NoCommasInPlaceHolders,
|
||||
NoEmbeddedImagesInSVG,
|
||||
OnlySMSCharacters,
|
||||
ValidEmail,
|
||||
ValidGovEmail,
|
||||
@@ -1133,7 +1134,8 @@ class SVGFileUpload(StripWhitespaceForm):
|
||||
'Upload an SVG logo',
|
||||
validators=[
|
||||
FileAllowed(['svg'], 'SVG Images only!'),
|
||||
DataRequired(message="You need to upload a file to submit")
|
||||
DataRequired(message="You need to upload a file to submit"),
|
||||
NoEmbeddedImagesInSVG()
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -80,6 +80,16 @@ class NoCommasInPlaceHolders:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class NoEmbeddedImagesInSVG:
|
||||
|
||||
def __init__(self, message='This SVG has an embedded raster image in it and will not render well'):
|
||||
self.message = message
|
||||
|
||||
def __call__(self, form, field):
|
||||
if '<image' in field.data.stream.read().decode("utf-8"):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class OnlySMSCharacters:
|
||||
def __call__(self, form, field):
|
||||
non_sms_characters = sorted(list(SanitiseSMS.get_non_compatible_characters(field.data)))
|
||||
|
||||
Reference in New Issue
Block a user