Commit b09b1674 authored by 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.
parent ce1519d2
...@@ -352,6 +352,8 @@ def find(): ...@@ -352,6 +352,8 @@ def find():
'subtext' 'subtext'
>>> ET.ElementTree(elem).findtext("section/tag") >>> ET.ElementTree(elem).findtext("section/tag")
'subtext' 'subtext'
>>> ET.XML('<root><empty /></root>').findtext('empty')
''
>>> summarize_list(elem.findall(".")) >>> summarize_list(elem.findall("."))
['body'] ['body']
>>> summarize_list(elem.findall("tag")) >>> summarize_list(elem.findall("tag"))
......
...@@ -840,7 +840,7 @@ element_findtext(ElementObject* self, PyObject* args) ...@@ -840,7 +840,7 @@ element_findtext(ElementObject* self, PyObject* args)
PyObject* text = element_get_text(item); PyObject* text = element_get_text(item);
if (text == Py_None) if (text == Py_None)
return PyBytes_FromString(""); return PyUnicode_FromString("");
Py_XINCREF(text); Py_XINCREF(text);
return 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