ploneplone-4.xploneformgen

UnicodeDecodeError in PloneFormGen after Plone Security patch 20161129


After applying the Plone security patch 20161129 our PloneFormGen form does not work anymore, because it contains Umlauts (ä, ö, ß or €). We use PloneFormGen 1.7.20 which is the recommended version for Plone 4.3.9. Here's the stacktrace:

  Module zope.tales.tales, line 696, in evaluate
   - URL: file:/var/plone/buildout-cache/eggs/Products.PloneFormGen-1.7.20-py2.7.egg/Products/PloneFormGen/skins/PloneFormGen/widget_fieldset_start.pt
   - Line 25, Column 10
   - Expression: <PythonExpr widget.Description(here)>
   - Names:
      {'container': <PloneSite at /mysite>,
       'context': <FormFolder at /mysite/mitglied-werden>,
       'desitelt': <object object at 0x7fe244f734b0>,
       'here': <FormFolder at /mysite/mitglied-werden>,
       'loop': {u'field': <Products.PageTemplates.Expressions.PathIterator object at 0x16fe5350>},
       'nothing': None,
       'options': {'args': (),
                   'state': <Products.CMFFormController.ControllerState.ControllerState object at 0x7fe22c676610>},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x1d61fc00>,
       'request': <HTTPRequest, URL=https://www.example.org/mitglied-werden/fg_base_view_p3>,
       'root': <Application at >,
       'template': <FSControllerPageTemplate at /mysite/fg_base_view_p3 used for /mysite/mitglied-werden>,
       'traverse_subpath': [],
       'user': <PloneUser 'siteb390'>}
  Module Products.PageTemplates.ZRPythonExpr, line 48, in __call__
   - __traceback_info__: widget.Description(here)
  Module PythonExpr, line 1, in <expression>
  Module Products.PloneFormGen.content.field_utils, line 27, in wDescription
  Module zope.i18n, line 107, in translate
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 20: ordinal not in range(128)

After removing the umlauts it works again, but the form looks a bit unprofessional now.

After searching the web for one hour now for just this error, I have no particular idea which extension causes this (PloneFormGen?) causes this and how to fix it :-/ Even no idea on which direction to look further...


Solution

  • Starting with 1.7.20, all PFG description fields are pushed through the translation mechanism. (Please don't ask me why they do that with user-supplied fields, because the description field is not language-insensitive in the first place.) Ths imposes additional limitations on what letters you can use in the description, as you have found.

    Not claiming that this is a bugfix, but in my quick trial, modifying buildout-cache/eggs/Products.PloneFormGen-1.7.20-py2.7.egg/Products/PloneFormGen/content/field_utils.py line 27 from

            if value:
            value = translate(value, context=instance.REQUEST)
            return cgi.escape(value)
    

    to

        if value:
            value = translate(value.decode('utf-8'), context=instance.REQUEST)
            return cgi.escape(value)
    

    made the problem go away.