Commit 96a69524 authored by Jérome Perrin's avatar Jérome Perrin

Formulator: validate TALES expressions in ZMI

Refuse setting an invalid TALES expression while saving in the ZMI.
parent c020b284
from __future__ import absolute_import
import string
from .DummyField import fields
from .Errors import ValidationError
from . import Widget, Validator
from Persistence import Persistent
import Acquisition
......@@ -77,6 +78,10 @@ except ImportError:
class TALESValidator(Validator.StringBaseValidator):
message_names = Validator.StringBaseValidator.message_names +\
['invalid']
invalid = 'The TALES expression is invalid.'
def validate(self, field, key, REQUEST):
value = Validator.StringBaseValidator.validate(self, field, key,
REQUEST)
......@@ -84,6 +89,11 @@ class TALESValidator(Validator.StringBaseValidator):
if value == "" and not field.get_value('required'):
return value
try:
getEngine().compile(value)
except (SyntaxError, getEngine().getCompilerError()) as e:
raise ValidationError('invalid', field, error_text=str(e))
return TALESMethod(value)
TALESValidatorInstance = TALESValidator()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment