# HG changeset patch # User hodgestar # Date 1359221207 0 # Node ID 0f4b2e892a4812efb852ff753025d3bb946f5609 # Parent 16ccaf7389d54c93f7b464e1125126f898cc14cd Fix handling of processing instructions that don't have data attached (patch from Neil Muller, fixes #368). diff --git a/genshi/input.py b/genshi/input.py --- 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): diff --git a/genshi/tests/input.py b/genshi/tests/input.py --- 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'' + 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'...' + 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 = '' events = list(XMLParser(StringIO(text)))