MetaDataXML: encode unicode file paths safely
authorZac Medico <zmedico@gentoo.org>
Wed, 12 Sep 2012 04:46:43 +0000 (21:46 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 12 Sep 2012 04:46:43 +0000 (21:46 -0700)
This will fix cases similar to the one fixed in commit
f01d7a8ca158ec60df76a3e8ae5b80ac3f62429e for bug #310789.

pym/portage/xml/metadata.py

index f820e5414b99323de4ecc48b3fa737fd8d382e45..113b118a439443bea1f1b05570ee52b4f68e74ff 100644 (file)
@@ -58,8 +58,7 @@ except (ImportError, SystemError, RuntimeError, Exception):
 
 import re
 import xml.etree.ElementTree
-import portage
-from portage import os, _unicode_decode
+from portage import _encodings, _unicode_encode, _unicode_decode
 from portage.util import unique_everseen
 
 class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
@@ -203,7 +202,8 @@ class MetaDataXML(object):
                self._xml_tree = None
 
                try:
-                       self._xml_tree = etree.parse(metadata_xml_path,
+                       self._xml_tree = etree.parse(_unicode_encode(metadata_xml_path,
+                               encoding=_encodings['fs'], errors='strict'),
                                parser=etree.XMLParser(target=_MetadataTreeBuilder()))
                except ImportError:
                        pass
@@ -241,7 +241,8 @@ class MetaDataXML(object):
 
                if self._herdstree is None:
                        try:
-                               self._herdstree = etree.parse(self._herds_path,
+                               self._herdstree = etree.parse(_unicode_encode(self._herds_path,
+                                       encoding=_encodings['fs'], errors='strict'),
                                        parser=etree.XMLParser(target=_MetadataTreeBuilder()))
                        except (ImportError, IOError, SyntaxError):
                                return None