summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-01-13 13:26:07 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-01-13 13:26:07 (GMT)
commit25771b3749cac588ad2ecc8fc796a496d35769e5 (patch)
treea52dd4608188b760df8202c60501f51fa275bd4c
parenta9edb6c4d1daa0749547a115ee4b02cc5b8d8ecd (diff)
downloadcpython-25771b3749cac588ad2ecc8fc796a496d35769e5.zip
cpython-25771b3749cac588ad2ecc8fc796a496d35769e5.tar.gz
cpython-25771b3749cac588ad2ecc8fc796a496d35769e5.tar.bz2
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
Patch by Serhiy Storchaka.
-rw-r--r--Lib/test/test_xml_etree.py3
-rw-r--r--Modules/_elementtree.c2
2 files changed, 4 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 59a8508..b4edd74 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -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)
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 274c65e..49441cc 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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;
}