Skip to content

Fix trailing slash handling in pkg_resources.ZipProvider#1232

Merged
jaraco merged 5 commits into
pypa:masterfrom
duggelz:dgreiman/issue1188
Dec 25, 2017
Merged

Fix trailing slash handling in pkg_resources.ZipProvider#1232
jaraco merged 5 commits into
pypa:masterfrom
duggelz:dgreiman/issue1188

Conversation

@duggelz

@duggelz duggelz commented Dec 12, 2017

Copy link
Copy Markdown

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.

Fixes #1188

Doug Greiman added 2 commits December 11, 2017 16:32
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.

@jaraco jaraco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. No objections to include. Could you add a changelog entry to CHANGES.txt for a new release with an 0.0.1 bump?

Comment thread pkg_resources/__init__.py Outdated
# 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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these two lines be fspath = fspath.rstrip(os.sep)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@duggelz

duggelz commented Dec 22, 2017

Copy link
Copy Markdown
Author

Added changelog entry, bumped version number, and rebased to head. Thanks.

@jaraco jaraco merged commit 1ad2c11 into pypa:master Dec 25, 2017
@jaraco

jaraco commented Dec 25, 2017

Copy link
Copy Markdown
Member

Excellent. With those changes, I can cut the release from my comm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent handling of trailing slashes in pkg_resources.ZipProvider.resource_listdir()

2 participants