Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.

Patch by Serhiy Storchaka.
This commit is contained in:
Eli Bendersky 2013-01-13 05:26:07 -08:00
parent a9edb6c4d1
commit 25771b3749
2 changed files with 4 additions and 1 deletions

View File

@ -1773,6 +1773,9 @@ class ElementFindTest(unittest.TestCase):
self.assertIsNone(e.findtext('tog'))
self.assertEqual(e.findtext('tog', 'default'), 'default')
# Issue #16922
self.assertEqual(ET.XML('<tag><empty /></tag>').findtext('empty'), '')
def test_findall(self):
e = ET.XML(SAMPLE_XML)
e[2] = ET.XML(SAMPLE_SECTION)

View File

@ -1129,7 +1129,7 @@ element_findtext(ElementObject *self, PyObject *args, PyObject *kwds)
PyObject* text = element_get_text(item);
if (text == Py_None)
return PyBytes_FromString("");
return PyUnicode_New(0, 0);
Py_XINCREF(text);
return text;
}