diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-01-13 13:26:31 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-01-13 13:26:31 (GMT) |
commit | a50ff1887d706ff193b698013931516307972382 (patch) | |
tree | cd27322e99348d8d3358908e112fbb0bb49a81b1 | |
parent | e5bdfef74289ce946d33b489a3c9e4db7b673d77 (diff) | |
parent | 25771b3749cac588ad2ecc8fc796a496d35769e5 (diff) | |
download | cpython-a50ff1887d706ff193b698013931516307972382.zip cpython-a50ff1887d706ff193b698013931516307972382.tar.gz cpython-a50ff1887d706ff193b698013931516307972382.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.py | 3 | ||||
-rw-r--r-- | Modules/_elementtree.c | 2 |
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; } |