libcomps/SOURCES/0001-Dont-print-empty-requires.patch
2021-10-08 12:34:57 +00:00

47 lines
1.9 KiB
Diff

From 7c999e57303d9b0afffde7354742988388fade3f Mon Sep 17 00:00:00 2001
From: Aleš Matěj <amatej@redhat.com>
Date: Thu, 15 Apr 2021 09:35:06 +0200
Subject: [PATCH] Don't print empty requires
The function `comps_object_tostr` used to get the string returns either
a valid value or if there is none it returns allocated "0" char.
Closes: https://github.com/rpm-software-management/libcomps/issues/23
---
libcomps/src/comps_docpackage.c | 5 +++--
libcomps/src/python/tests/__test.py | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libcomps/src/comps_docpackage.c b/libcomps/src/comps_docpackage.c
index 07cc30a..331036e 100644
--- a/libcomps/src/comps_docpackage.c
+++ b/libcomps/src/comps_docpackage.c
@@ -169,8 +169,9 @@ signed char comps_docpackage_xml(COMPS_DocGroupPackage *pkg,
if (pkg->requires) {
str = comps_object_tostr((COMPS_Object*)pkg->requires);
- ret = xmlTextWriterWriteAttribute(writer, (xmlChar*) "requires",
- BAD_CAST str);
+ if (str && *str) {
+ ret = xmlTextWriterWriteAttribute(writer, (xmlChar*) "requires", BAD_CAST str);
+ }
free(str);
}
COMPS_XMLRET_CHECK()
diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
index 2b321e3..35a41f7 100644
--- a/libcomps/src/python/tests/__test.py
+++ b/libcomps/src/python/tests/__test.py
@@ -626,7 +626,7 @@ class PackageTest(unittest.TestCase):
self.comps.groups[0].packages.append(libcomps.Package("kernel", libcomps.PACKAGE_TYPE_MANDATORY))
out = self.comps.xml_str()
- self.assertTrue("<packagereq type=\"mandatory\" requires=\"\">kernel</packagereq>" in out)
+ self.assertTrue("<packagereq type=\"mandatory\">kernel</packagereq>" in out)
#@unittest.skip("skip")
class DictTest(unittest.TestCase):
--
libgit2 1.0.1