Kaydet (Commit) 25771b37 authored tarafından Eli Bendersky's avatar Eli Bendersky

Issue #16922: fixed findtext() to return empty Unicode string instead of empty…

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

Patch by Serhiy Storchaka.
üst a9edb6c4
......@@ -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)
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment