From 7b8b56fa28fc9ee4cd6e0156074505e3fef620e3 Mon Sep 17 00:00:00 2001 From: Doug Greiman Date: Sun, 5 Nov 2017 05:43:48 -0800 Subject: 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. --- pkg_resources/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pkg_resources') 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( -- cgit v1.2.3