[Yum-devel] [PATCH] ensure all attribute values are utf-8-encoded strs and properly xml-attribute-escaped

Mike Bonnet mikeb at redhat.com
Tue Aug 4 22:22:33 UTC 2009


When reading package metadata out of a database, sqlite returns unicode objects.  If we then use this data to generate new XML files (as mergerepo does), any string that gets concatenated with this data gets coerced to a unicode, using the default ascii codec.  If the string contains utf-8-encoded chars, then the ascii codec fails, and we get UnicodeDecodeErrors.  This patch ensures that package metadata is converted to utf-8-encoded strs before concatenation, avoiding the errors, as well as ensuring that the metadata is property xml-escaped for use in attribute values.

---
  yum/packages.py |   18 +++++++++---------
  1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/yum/packages.py b/yum/packages.py
index a7e81e6..af33d94 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -863,13 +863,13 @@ class YumAvailablePackage(PackageObject, RpmBase):
          for (name, flags, (e,v,r)) in mylist:
              pcostring = '''      <rpm:entry name="%s"''' % misc.to_xml(name, attrib=True)
              if flags:
-                pcostring += ''' flags="%s"''' % flags
+                pcostring += ''' flags="%s"''' % misc.to_xml(flags, attrib=True)
                  if e:
-                    pcostring += ''' epoch="%s"''' % e
+                    pcostring += ''' epoch="%s"''' % misc.to_xml(e, attrib=True)
                  if v:
-                    pcostring += ''' ver="%s"''' % v
+                    pcostring += ''' ver="%s"''' % misc.to_xml(v, attrib=True)
                  if r:
-                    pcostring += ''' rel="%s"''' % r
+                    pcostring += ''' rel="%s"''' % misc.to_xml(r, attrib=True)
                      
              pcostring += "/>\n"
              msg += pcostring
@@ -934,15 +934,15 @@ class YumAvailablePackage(PackageObject, RpmBase):
                  continue
              prcostring = '''      <rpm:entry name="%s"''' % misc.to_xml(name, attrib=True)
              if flags:
-                prcostring += ''' flags="%s"''' % flags
+                prcostring += ''' flags="%s"''' % misc.to_xml(flags, attrib=True)
                  if e:
-                    prcostring += ''' epoch="%s"''' % e
+                    prcostring += ''' epoch="%s"''' % misc.to_xml(e, attrib=True)
                  if v:
-                    prcostring += ''' ver="%s"''' % v
+                    prcostring += ''' ver="%s"''' % misc.to_xml(v, attrib=True)
                  if r:
-                    prcostring += ''' rel="%s"''' % r
+                    prcostring += ''' rel="%s"''' % misc.to_xml(r, attrib=True)
              if pre:
-                prcostring += ''' pre="%s"''' % pre
+                prcostring += ''' pre="%s"''' % misc.to_xml(pre, attrib=True)
                      
              prcostring += "/>\n"
              msg += prcostring
-- 
1.6.0.6


More information about the Yum-devel mailing list