Skip to content

Commit

Permalink
Fix rare case when a "non friendly" type is looked up in `plone.app.v…
Browse files Browse the repository at this point in the history
…ocabularies.ReallyUserFriendlyTypes`

this came up in `collective.collectionfilter` when `Plone Site` type is in filteritems.

The code here was basically a false `urllib.parse` migration to python3
  • Loading branch information
petschki committed Jan 16, 2025
1 parent cc20782 commit 870a74d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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 870a74d

Please sign in to comment.