Skip to content

Commit

Permalink
Added validation for identifiers token INameTokenTableRowSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
odelaere committed Jun 7, 2022
1 parent 44e172f commit 5d73f56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,8 @@ Changelog

- Added `safe_utils.py` that will only include safe utils.
[gbastien]
- Added validation for identifiers token INameTokenTableRowSchema.
[odelaere]

1.38 (2022-02-03)
-----------------
Expand Down
8 changes: 7 additions & 1 deletion src/collective/contact/core/content/directory.py
Expand Up @@ -5,8 +5,10 @@
from plone.autoform.directives import widget
from plone.dexterity.content import Container
from plone.dexterity.schema import DexteritySchemaPolicy
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.supermodel import model
from zope import schema
from zope.component import getUtility
from zope.interface import implements
from zope.interface import Interface

Expand All @@ -16,8 +18,12 @@ class INameTokenTableRowSchema(Interface):
name is the 'real' name
token is the token used in the vocabularies
"""
def is_valid_identifier(identifier):
idnormalizer = getUtility(IIDNormalizer)
return idnormalizer.normalize(identifier) == identifier

name = schema.TextLine(title=_(u"Name"))
token = schema.TextLine(title=_(u"Token"))
token = schema.TextLine(title=_(u"Token"), constraint=is_valid_identifier)


class IDirectory(model.Schema):
Expand Down

0 comments on commit 5d73f56

Please sign in to comment.