mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 01:55:41 -04:00
Merge pull request #1768 from GSA/comma-escape-b
don't allow commas in placeholder fields
This commit is contained in:
@@ -50,6 +50,7 @@ from app.main.validators import (
|
|||||||
CommonlyUsedPassword,
|
CommonlyUsedPassword,
|
||||||
CsvFileValidator,
|
CsvFileValidator,
|
||||||
DoesNotStartWithDoubleZero,
|
DoesNotStartWithDoubleZero,
|
||||||
|
FieldCannotContainComma,
|
||||||
LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly,
|
LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly,
|
||||||
MustContainAlphanumericCharacters,
|
MustContainAlphanumericCharacters,
|
||||||
NoCommasInPlaceHolders,
|
NoCommasInPlaceHolders,
|
||||||
@@ -1650,7 +1651,11 @@ def get_placeholder_form_instance(
|
|||||||
) # TODO: replace with us_mobile_number
|
) # TODO: replace with us_mobile_number
|
||||||
else:
|
else:
|
||||||
field = GovukTextInputField(
|
field = GovukTextInputField(
|
||||||
placeholder_name, validators=[DataRequired(message="Cannot be empty")]
|
placeholder_name,
|
||||||
|
validators=[
|
||||||
|
DataRequired(message="Cannot be empty"),
|
||||||
|
FieldCannotContainComma(),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
PlaceholderForm.placeholder_value = field
|
PlaceholderForm.placeholder_value = field
|
||||||
|
|||||||
@@ -161,6 +161,15 @@ class DoesNotStartWithDoubleZero:
|
|||||||
raise ValidationError(self.message)
|
raise ValidationError(self.message)
|
||||||
|
|
||||||
|
|
||||||
|
class FieldCannotContainComma:
|
||||||
|
def __init__(self, message="Cannot contain a comma"):
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
def __call__(self, form, field):
|
||||||
|
if field.data and "," in field.data:
|
||||||
|
raise ValidationError(self.message)
|
||||||
|
|
||||||
|
|
||||||
class MustContainAlphanumericCharacters:
|
class MustContainAlphanumericCharacters:
|
||||||
regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*")
|
regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user