From 6b43fbc5eac1564252fb2715fe304773851d350b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 25 Mar 2016 23:25:39 +0100 Subject: [PATCH 2/2] prevent non utf-8 strings from breaking /inspect (#10447) --- wcs/backoffice/management.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wcs/backoffice/management.py b/wcs/backoffice/management.py index 0d4735e..c938053 100644 --- a/wcs/backoffice/management.py +++ b/wcs/backoffice/management.py @@ -1623,7 +1623,7 @@ class FormPage(Directory): class FormBackOfficeStatusPage(FormStatusPage): - _q_exports = ['', 'download', 'json', 'action', 'inspect'] + _q_exports = ['', 'download', 'json', 'action', 'inspect', 'validate'] form_page_class = FormFillPage def html_top(self, title = None): @@ -1805,6 +1805,7 @@ class FormBackOfficeStatusPage(FormStatusPage): if not (get_publisher().get_backoffice_root().is_accessible('forms') or get_publisher().get_backoffice_root().is_accessible('workflows')): raise errors.AccessForbiddenError() + charset = get_publisher().site_charset get_response().breadcrumb.append(('inspect', _('Form Inspector'))) self.html_top(self.formdef.name) r = TemplateIO(html=True) @@ -1814,9 +1815,23 @@ class FormBackOfficeStatusPage(FormStatusPage): r += htmltext('
  • %s

  • ') % _('Substitution variables') substvars = self.filled.get_substitution_variables() substvars.update(self.filled.formdef.get_substitution_variables()) + + def safe(v): + if isinstance(v, str): + try: + unicode(v, charset) + except UnicodeDecodeError: + v = repr(v) + else: + try: + v = unicode(v).encode(charset) + except UnicodeDecodeError: + v = repr(v) + return v for k, v in sorted(substvars.items()): + k = safe(k) r += htmltext('
  • %s') % (k, k) - r += htmltext('
    %s') % v + r += htmltext('
    %s') % safe(v) if not isinstance(v, basestring): r += htmltext(' (%s)') % type(v) r += htmltext('
    ') -- 2.1.4