summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Greiman <dgreiman@google.com>2017-11-05 05:43:48 -0800
committerDoug Greiman <dgreiman@google.com>2017-12-11 16:32:18 -0800
commit7b8b56fa28fc9ee4cd6e0156074505e3fef620e3 (patch)
tree594f9673c48216c40935195f1dd2bb682fa80dec
parent66729ab597c6bfddd128159fe0a6d13e7f95ce83 (diff)
downloadpython-setuptools-git-7b8b56fa28fc9ee4cd6e0156074505e3fef620e3.tar.gz
Fix trailing slash handling in pkg_resources.ZipProvider
Given a ZipProvider, if the underlying ZipImporter prefix is empty, then resource_listdir('') and resource_listdir('subdir/') fail, while resource_listdir('/') and resource_listdir('subdir') succeed. On the other hand, if the underlying ZipImport prefix is not empty, then resource_listdir('/') fails but resource_listdir('') succeeds. With this change, the cases listed succeed with or without trailing slashes.
-rw-r--r--pkg_resources/__init__.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 73334641..ffaf7aca 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -1693,6 +1693,10 @@ class ZipProvider(EggProvider):
def _zipinfo_name(self, fspath):
# Convert a virtual filename (full path to file) into a zipfile subpath
# usable with the zipimport directory cache for our target archive
+ while fspath.endswith(os.sep):
+ fspath = fspath[:-1]
+ if fspath == self.loader.archive:
+ return ''
if fspath.startswith(self.zip_pre):
return fspath[len(self.zip_pre):]
raise AssertionError(