summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp von Weitershausen <philipp@weitershausen.de>2007-01-14 13:54:17 +0000
committerPhilipp von Weitershausen <philipp@weitershausen.de>2007-01-14 13:54:17 +0000
commitae8fd91d9ee289f31a30cc7a435fd077dface481 (patch)
treedc75ea1e8c7f3b108b78c090bb9bbf6df0f6d47c
parent1dd9649c77ec7ddc0a8ce2d0029e43d9c112e1ad (diff)
downloadzope-tal-ae8fd91d9ee289f31a30cc7a435fd077dface481.tar.gz
Merge from 3.3 branch:backups/monolithic-zope3@75193
------------------------------------------------------------------------ r72022 | philikon | 2007-01-14 14:45:26 +0100 (Sun, 14 Jan 2007) | 5 lines zope.tal.xmlparser.XMLParser couldn't deal with unicode strings, which meant that PageTemplates in XML mode whose source code was available as a unicode string failed. Fixed the problem and added a test that exercises a PT w/ unicode source in XML mode (HTML mode already worked). ------------------------------------------------------------------------
-rw-r--r--tests/test_xmlparser.py6
-rw-r--r--xmlparser.py5
2 files changed, 11 insertions, 0 deletions
diff --git a/tests/test_xmlparser.py b/tests/test_xmlparser.py
index 3647872..02d5848 100644
--- a/tests/test_xmlparser.py
+++ b/tests/test_xmlparser.py
@@ -249,6 +249,12 @@ text
def test_declaration_junk_chars(self):
self._parse_error("<!DOCTYPE foo $ >")
+ def test_unicode_string(self):
+ output = [('starttag', u'p', []),
+ ('data', u'\xe4\xf6\xfc\xdf'),
+ ('endtag', u'p')]
+ self._run_check(u'<p>\xe4\xf6\xfc\xdf</p>', output)
+
# Support for the Zope regression test framework:
def test_suite(skipxml=utils.skipxml):
diff --git a/xmlparser.py b/xmlparser.py
index 593bcbe..aafa693 100644
--- a/xmlparser.py
+++ b/xmlparser.py
@@ -74,6 +74,11 @@ class XMLParser(object):
self.parseStream(open(filename))
def parseString(self, s):
+ if isinstance(s, unicode):
+ # Expat cannot deal with unicode strings, only with
+ # encoded ones. Also, its range of encodings is rather
+ # limited, UTF-8 is the safest bet here.
+ s = s.encode('utf-8')
self.parser.Parse(s, 1)
def parseURL(self, url):