From 499558e7bcb2ec6be80b93ee5b83f7490bf6f0a4 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Fri, 20 Jul 2018 02:17:00 -0400 Subject: [PATCH] Update requirementslib - Fix a bug which raised `UnboundLocalError` when parsing malformed urls - Fixes #2614 Signed-off-by: Dan Ryan --- news/2617.bugfix | 1 + news/2617.vendor | 1 + pipenv/vendor/requirementslib/__init__.py | 2 +- .../requirementslib/models/requirements.py | 2 +- pipenv/vendor/requirementslib/utils.py | 32 +++++++++++++++++-- pipenv/vendor/vendor.txt | 2 +- 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 news/2617.bugfix create mode 100644 news/2617.vendor diff --git a/news/2617.bugfix b/news/2617.bugfix new file mode 100644 index 00000000..2a2c5842 --- /dev/null +++ b/news/2617.bugfix @@ -0,0 +1 @@ +Update requirementslib to fix a bug which could raise an ``UnboundLocalError`` when parsing malformed VCS URIs. diff --git a/news/2617.vendor b/news/2617.vendor new file mode 100644 index 00000000..2a2c5842 --- /dev/null +++ b/news/2617.vendor @@ -0,0 +1 @@ +Update requirementslib to fix a bug which could raise an ``UnboundLocalError`` when parsing malformed VCS URIs. diff --git a/pipenv/vendor/requirementslib/__init__.py b/pipenv/vendor/requirementslib/__init__.py index 063458dc..eeb970c4 100644 --- a/pipenv/vendor/requirementslib/__init__.py +++ b/pipenv/vendor/requirementslib/__init__.py @@ -1,5 +1,5 @@ # -*- coding=utf-8 -*- -__version__ = "1.0.10" +__version__ = "1.0.11" from .exceptions import RequirementError diff --git a/pipenv/vendor/requirementslib/models/requirements.py b/pipenv/vendor/requirementslib/models/requirements.py index 177bd454..ff3bba73 100644 --- a/pipenv/vendor/requirementslib/models/requirements.py +++ b/pipenv/vendor/requirementslib/models/requirements.py @@ -176,10 +176,10 @@ class FileRequirement(BaseRequirement): # This is an URI. We'll need to perform some elaborated parsing. parsed_url = urllib_parse.urlsplit(fixed_line) + original_url = parsed_url._replace() if added_ssh_scheme and ':' in parsed_url.netloc: original_netloc, original_path_start = parsed_url.netloc.rsplit(':', 1) uri_path = '/{0}{1}'.format(original_path_start, parsed_url.path) - original_url = parsed_url parsed_url = original_url._replace(netloc=original_netloc, path=uri_path) # Split the VCS part out if needed. diff --git a/pipenv/vendor/requirementslib/utils.py b/pipenv/vendor/requirementslib/utils.py index 4c0d3e07..685a90b3 100644 --- a/pipenv/vendor/requirementslib/utils.py +++ b/pipenv/vendor/requirementslib/utils.py @@ -60,6 +60,19 @@ def is_vcs(pipfile_entry): return False +def check_for_unc_path(path): + """ Checks to see if a pathlib `Path` object is a unc path or not""" + if ( + os.name == "nt" + and len(path.drive) > 2 + and not path.drive[0].isalpha() + and path.drive[1] != ":" + ): + return True + else: + return False + + def get_converted_relative_path(path, relative_to=os.curdir): """Convert `path` to be relative. @@ -69,13 +82,26 @@ def get_converted_relative_path(path, relative_to=os.curdir): This performs additional conversion to ensure the result is of POSIX form, and starts with `./`, or is precisely `.`. """ - start = Path(relative_to) + + start_path = Path(relative_to) try: - start = start.resolve() + start = start_path.resolve() except OSError: - start = start.absolute() + start = start_path.absolute() + + # check if there is a drive letter or mount point + # if it is a mountpoint use the original absolute path + # instead of the unc path + if check_for_unc_path(start): + start = start_path.absolute() + path = start.joinpath(path).relative_to(start) + # check and see if the path that was passed into the function is a UNC path + # and raise value error if it is not. + if check_for_unc_path(path): + raise ValueError("The path argument does not currently accept UNC paths") + relpath_s = posixpath.normpath(path.as_posix()) if not (relpath_s == "." or relpath_s.startswith("./")): relpath_s = posixpath.join(".", relpath_s) diff --git a/pipenv/vendor/vendor.txt b/pipenv/vendor/vendor.txt index 2b7781ce..961ad016 100644 --- a/pipenv/vendor/vendor.txt +++ b/pipenv/vendor/vendor.txt @@ -27,7 +27,7 @@ requests==2.19.1 idna==2.7 urllib3==1.23 certifi==2018.4.16 -requirementslib==1.0.10 +requirementslib==1.0.11 attrs==18.1.0 distlib==0.2.7 packaging==17.1