diff --git a/libcomps/src/python/src/pycomps.c b/libcomps/src/python/src/pycomps.c index ffc9e71..c57c68a 100644 --- a/libcomps/src/python/src/pycomps.c +++ b/libcomps/src/python/src/pycomps.c @@ -360,7 +360,16 @@ PyObject* PyCOMPS_fromxml_str(PyObject *self, PyObject *args, PyObject *kwds) { Py_CLEAR(self_comps->p_whiteout); COMPS_OBJECT_DESTROY(self_comps->comps_doc); - self_comps->comps_doc = parsed->comps_doc; + if (parsed->comps_doc) { + self_comps->comps_doc = parsed->comps_doc; + } else { + COMPS_Object *tmpstr; + tmpstr = (COMPS_Object*)comps_str("UTF-8"); + self_comps->comps_doc = COMPS_OBJECT_CREATE(COMPS_Doc, + (COMPS_Object*[]){tmpstr}); + COMPS_OBJECT_DESTROY(tmpstr); + } + COMPS_OBJECT_DESTROY(self_comps->comps_doc->log); self_comps->comps_doc->log = parsed->log; parsed->log = NULL; diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py index 63a30e2..ba4b349 100644 --- a/libcomps/src/python/tests/__test.py +++ b/libcomps/src/python/tests/__test.py @@ -737,6 +737,13 @@ def test_xml(self): comps4 = libcomps.Comps() self.assertRaises(libcomps.ParserError, comps4.fromxml_str, str(INVALID_COMPS_XML)) + VALID_XML_NO_COMPS = "" + comps5 = libcomps.Comps() + ret = comps5.fromxml_str(str(VALID_XML_NO_COMPS)) + # return code 1 is non fatal error + self.assertTrue(ret == 1, comps5.get_last_errors()) + + #@unittest.skip("") def test_fedora(self): comps = libcomps.Comps()