From 870a74d875aed609b08fc3fa424690e9012e88be Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Thu, 16 Jan 2025 12:25:14 +0100 Subject: [PATCH 1/2] Fix rare case when a "non friendly" type is looked up in `plone.app.vocabularies.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 --- plone/app/vocabularies/__init__.py | 4 ++-- plone/app/vocabularies/types.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plone/app/vocabularies/__init__.py b/plone/app/vocabularies/__init__.py index f153ac9..2bb522b 100644 --- a/plone/app/vocabularies/__init__.py +++ b/plone/app/vocabularies/__init__.py @@ -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 @@ -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 diff --git a/plone/app/vocabularies/types.py b/plone/app/vocabularies/types.py index a921e9c..91dcfe1 100644 --- a/plone/app/vocabularies/types.py +++ b/plone/app/vocabularies/types.py @@ -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): From a9796ecaec6280aad26632f453ab0f6cfbb494d7 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Thu, 16 Jan 2025 12:27:15 +0100 Subject: [PATCH 2/2] changenote --- news/99.bugfix | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/99.bugfix diff --git a/news/99.bugfix b/news/99.bugfix new file mode 100644 index 0000000..52d8488 --- /dev/null +++ b/news/99.bugfix @@ -0,0 +1,2 @@ +Fix rare case of "non friendly" token lookup in `plone.app.vocabularies.ReallyUserFriendlyTypes` +[petschki]