mirror of https://github.com/python/cpython
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:
parent
a9edb6c4d1
commit
25771b3749
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue