Commit 8fffd3f8 authored by Jérome Perrin's avatar Jérome Perrin

xhtml_style: fix rendering of standard_error_message when site title is not ASCII

When rendering error page, the default header_title is computed in global_definitions
and this is done by concatenating string:ERP5 (which is unicode) and the
title of the portal (which is an UTF-8 encoded string), which causes an
UnicodeDecodeError, because the portal title was decoded as ASCII.

Because header_title is usually an UTF-8 encoded string, also use an UTF-8
encoded string for 'ERP5' default value.
parent 9d9df4fe
##############################################################################
#
# coding: utf-8
# Copyright (c) 2004, 2005, 2006 Nexedi SARL and Contributors.
# All Rights Reserved.
# Romain Courteaud <romain@nexedi.com>
......@@ -32,6 +32,7 @@ import httplib
import urlparse
import base64
import urllib
import lxml.html
from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase
......@@ -647,6 +648,31 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(response.status, 401)
self.assertEqual(response.getheader('WWW-Authenticate'), None)
def test_non_ascii_site_title(self):
self.portal.setTitle('文字化け')
self.assertEqual(
lxml.html.fromstring(self.portal.view()).find('.//div[@id="breadcrumb"]/a').text,
u'文字化け')
self.assertEqual(
lxml.html.fromstring(
self.portal.person_module.view()
).find('.//div[@id="breadcrumb"]/a').text,
u'文字化け')
self.assertEqual(
lxml.html.fromstring(
self.portal.person_module.newContent(portal_type='Person').view()
).find('.//div[@id="breadcrumb"]/a').text,
u'文字化け')
def test_standard_error_message_non_ascii(self):
# regression test for error message when portal title is not ASCII
self.portal.setTitle('文字化け')
self.assertIn(
u'文字化け',
self.portal.standard_error_message(
error_type="MyErrorType",
error_message="my error message."))
def test_standardErrorMessageShouldNotRaiseUnauthorizeOnUnauthorizeDocument(self):
"""
When trying to show the `standard_error_message` on a document that user
......
......@@ -46,7 +46,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title
tal:define="
title title | string:ERP5;
title title | python:'ERP5';
header_title header_title | nothing;
"
tal:content="python: header_title or '%s | %s' % (title, here.getPortalObject().title_or_id())"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment