From fg at nuxeo.com Thu Jan 30 15:14:38 2003 From: fg at nuxeo.com (Florent Guillaume) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests - test_talinterpreter.py:1.3.100.4 Message-ID: <200301302014.h0UKEct24263@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL/tests In directory cvs.zope.org:/tmp/cvs-serv23953/lib/python/TAL/tests Modified Files: Tag: Zope-2_6-branch test_talinterpreter.py Log Message: Merge an old bugfix from HEAD that hadn't been merged yet: Collector #721: preserve syntactically valid character entities in attributes. === Zope/lib/python/TAL/tests/test_talinterpreter.py 1.3.100.3 => 1.3.100.4 === --- Zope/lib/python/TAL/tests/test_talinterpreter.py:1.3.100.3 Thu Jan 30 13:57:12 2003 +++ Zope/lib/python/TAL/tests/test_talinterpreter.py Thu Jan 30 15:14:33 2003 @@ -63,29 +63,17 @@ attributes=", so" the="output" needs="to" be="line" wrapped="."> ''' "\n" - program, macros = self._compile(INPUT) - sio = StringIO() - interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60) - interp() - self.assertEqual(sio.getvalue(), EXPECTED) + self.compare(INPUT, EXPECTED) def check_unicode_content(self): INPUT = """

para

""" EXPECTED = u"""

déjà-vu

""" "\n" - program, macros = self._compile(INPUT) - sio = StringIO() - interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60) - interp() - self.assertEqual(sio.getvalue(), EXPECTED) + self.compare(INPUT, EXPECTED) def check_unicode_structure(self): INPUT = """

para

""" EXPECTED = u"""déjà-vu""" "\n" - program, macros = self._compile(INPUT) - sio = StringIO() - interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60) - interp() - self.assertEqual(sio.getvalue(), EXPECTED) + self.compare(INPUT, EXPECTED) def check_i18n_replace_number(self): INPUT = """ @@ -94,15 +82,21 @@

""" EXPECTED = u"""

FOO 123

""" "\n" - program, macros = self._compile(INPUT) - sio = StringIO() - interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60) - interp() - self.assertEqual(sio.getvalue(), EXPECTED) + self.compare(INPUT, EXPECTED) + + def check_entities(self): + INPUT = ('') + EXPECTED = ('&a;  
 '
+                    '&a &#45 &; &#0a; <>\n') + self.compare(INPUT, EXPECTED) def check_escaping(self): INPUT = """

""" EXPECTED = "

"<>&

\n" + self.compare(INPUT, EXPECTED) + + def compare(self, INPUT, EXPECTED): program, macros = self._compile(INPUT) sio = StringIO() interp = TALInterpreter(program, {}, DummyEngine(), sio, wrap=60) From fg at nuxeo.com Thu Jan 30 15:15:06 2003 From: fg at nuxeo.com (Florent Guillaume) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - TALDefs.py:1.28.6.4 TALGenerator.py:1.55.6.4 Message-ID: <200301302015.h0UKF6l24457@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL In directory cvs.zope.org:/tmp/cvs-serv23953/lib/python/TAL Modified Files: Tag: Zope-2_6-branch TALDefs.py TALGenerator.py Log Message: Merge an old bugfix from HEAD that hadn't been merged yet: Collector #721: preserve syntactically valid character entities in attributes. === Zope/lib/python/TAL/TALDefs.py 1.28.6.3 => 1.28.6.4 === --- Zope/lib/python/TAL/TALDefs.py:1.28.6.3 Mon Oct 28 15:45:50 2002 +++ Zope/lib/python/TAL/TALDefs.py Thu Jan 30 15:14:30 2003 @@ -164,3 +164,24 @@ if opcode == "version": return version return None + +import re +_ent1_re = re.compile('&(?![A-Z#])', re.I) +_entch_re = re.compile('&([A-Z][A-Z0-9]*)(?![A-Z0-9;])', re.I) +_entn1_re = re.compile('&#(?![0-9X])', re.I) +_entnx_re = re.compile('&(#X[A-F0-9]*)(?![A-F0-9;])', re.I) +_entnd_re = re.compile('&(#[0-9][0-9]*)(?![0-9;])') +del re + +def attrEscape(s): + """Replace special characters '&<>' by character entities, + except when '&' already begins a syntactically valid entity.""" + s = _ent1_re.sub('&', s) + s = _entch_re.sub(r'&\1', s) + s = _entn1_re.sub('&#', s) + s = _entnx_re.sub(r'&\1', s) + s = _entnd_re.sub(r'&\1', s) + s = s.replace('<', '<') + s = s.replace('>', '>') + s = s.replace('"', '"') + return s === Zope/lib/python/TAL/TALGenerator.py 1.55.6.3 => 1.55.6.4 === --- Zope/lib/python/TAL/TALGenerator.py:1.55.6.3 Tue Oct 1 11:54:26 2002 +++ Zope/lib/python/TAL/TALGenerator.py Thu Jan 30 15:14:31 2003 @@ -162,7 +162,7 @@ if item[1] is None: s = item[0] else: - s = '%s="%s"' % (item[0], cgi.escape(item[1], 1)) + s = '%s="%s"' % (item[0], TALDefs.attrEscape(item[1])) attrlist[i] = item[0], s new.append(" " + s) # if no non-optimizable attributes were found, convert to plain text