Skip to content

Commit

Permalink
Merge pull request #99 from plone/petschki-types-vocab-fallback
Browse files Browse the repository at this point in the history
Fix token lookup in `ReallyUserFriendlyTypes`
  • Loading branch information
mauritsvanrees authored Jan 16, 2025
2 parents cc20782 + a9796ec commit 5f3c42e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions news/99.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix rare case of "non friendly" token lookup in `plone.app.vocabularies.ReallyUserFriendlyTypes`
[petschki]
4 changes: 2 additions & 2 deletions plone/app/vocabularies/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from plone.app.vocabularies.interfaces import IPermissiveVocabulary
from plone.app.vocabularies.interfaces import ISlicableVocabulary
from urllib import parse
from urllib.parse import unquote
from zope.interface import directlyProvides
from zope.interface import implementer
from zope.schema.vocabulary import SimpleTerm
Expand Down Expand Up @@ -57,5 +57,5 @@ def getTermByToken(self, token):
v = super().getTermByToken(token)
except LookupError:
# fallback using dummy term, assumes token==value
return SimpleTerm(token, title=parse(token))
return SimpleTerm(token, title=unquote(token))
return v
6 changes: 4 additions & 2 deletions plone/app/vocabularies/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ class ReallyUserFriendlyTypesVocabulary:
Containment is unenforced, to make GenericSetup import validation
handle validation triggered by Choice.fromUnicode() on insertion:
>>> assert 'arbitrary_value' in util(context)
>>> non_friendly_type = types.getTermByToken('Plone Site')
>>> non_friendly_type.title, non_friendly_type.token
('Plone Site', 'Plone Site')
>>> doc = types.by_token['Document']
>>> doc.title, doc.token, doc.value
(u'Page', 'Document', 'Document')
('Page', 'Document', 'Document')
"""

def __call__(self, context):
Expand Down

0 comments on commit 5f3c42e

Please sign in to comment.