Don’t allow commas in placeholders

> If a user tries to save a template containing something like
> ((name,date)) we should give a validation error.

This is because it causes havoc with the column headers in CSV files.

https://www.pivotaltracker.com/story/show/117043389
This commit is contained in:
Chris Hill-Scott
2016-04-07 16:02:06 +01:00
parent ab8a5c561f
commit dfd8540b54
3 changed files with 26 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import re
from wtforms import ValidationError
from datetime import datetime
from app.main.encryption import check_hash
from utils.template import Template
class Blacklist(object):
@@ -38,3 +39,13 @@ class ValidEmailDomainRegex(object):
email_regex = "[^\@^\s]+@([^@^\\.^\\s]+\.)*({})$".format("|".join(valid_domains))
if not re.match(email_regex, field.data.lower()):
raise ValidationError(message)
class NoCommasInPlaceHolders():
def __init__(self, message='You cant have commas in your fields'):
self.message = message
def __call__(self, form, field):
if ',' in ''.join(Template({'content': field.data}).placeholders):
raise ValidationError(self.message)