Mercurial > genshi > mirror
changeset 996:0f4b2e892a48 trunk
Fix handling of processing instructions that don't have data attached (patch from Neil Muller, fixes #368).
author | hodgestar |
---|---|
date | Sat, 26 Jan 2013 17:26:47 +0000 |
parents | 16ccaf7389d5 |
children | d599d55a9a70 |
files | genshi/input.py genshi/tests/input.py |
diffstat | 2 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/genshi/input.py +++ b/genshi/input.py @@ -401,9 +401,14 @@ self._enqueue(TEXT, text) def handle_pi(self, data): - target, data = data.split(None, 1) if data.endswith('?'): data = data[:-1] + try: + target, data = data.split(None, 1) + except ValueError: + # PI with no data + target = data + data = '' self._enqueue(PI, (target.strip(), data.strip())) def handle_comment(self, text):
--- a/genshi/tests/input.py +++ b/genshi/tests/input.py @@ -177,6 +177,25 @@ self.assertEqual('php', target) self.assertEqual('echo "Foobar"', data) + def test_processing_instruction_no_data_1(self): + text = u'<?foo ?>' + events = list(HTMLParser(StringIO(text))) + kind, (target, data), pos = events[0] + self.assertEqual(Stream.PI, kind) + self.assertEqual('foo', target) + self.assertEqual('', data) + + def test_processing_instruction_no_data_2(self): + text = u'<?experiment>...<?/experiment>' + events = list(HTMLParser(StringIO(text))) + kind, (target, data), pos = events[0] + self.assertEqual(Stream.PI, kind) + self.assertEqual('experiment', target) + self.assertEqual('', data) + kind, (target, data), pos = events[2] + self.assertEqual('/experiment', target) + self.assertEqual('', data) + def test_xmldecl(self): text = '<?xml version="1.0" ?><root />' events = list(XMLParser(StringIO(text)))