Mercurial > genshi > genshi-test
changeset 376:74b6bf92f0cd
Fix parsing of processing instructions in HTML input.
author | cmlenz |
---|---|
date | Thu, 23 Nov 2006 11:28:15 +0000 |
parents | 5b859df8b184 |
children | 79a7db5177e9 |
files | genshi/input.py genshi/tests/input.py |
diffstat | 2 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/genshi/input.py +++ b/genshi/input.py @@ -349,8 +349,9 @@ self._enqueue(TEXT, text) def handle_pi(self, data): - target, data = data.split(maxsplit=1) - data = data.rstrip('?') + target, data = data.split(None, 1) + if data.endswith('?'): + data = data[:-1] self._enqueue(PI, (target.strip(), data.strip())) def handle_comment(self, text):
--- a/genshi/tests/input.py +++ b/genshi/tests/input.py @@ -173,6 +173,22 @@ self.assertEqual(Stream.TEXT, kind) self.assertEqual(u'\xa0', data) + def test_processing_instruction(self): + text = '<?php echo "Foobar" ?>' + events = list(HTMLParser(StringIO(text))) + kind, (target, data), pos = events[0] + self.assertEqual(Stream.PI, kind) + self.assertEqual(u'php', target) + self.assertEqual(u'echo "Foobar"', data) + + def test_processing_instruction_trailing_qmark(self): + text = '<?php echo "Foobar" ??>' + events = list(HTMLParser(StringIO(text))) + kind, (target, data), pos = events[0] + self.assertEqual(Stream.PI, kind) + self.assertEqual(u'php', target) + self.assertEqual(u'echo "Foobar" ?', data) + def suite(): suite = unittest.TestSuite()