Skip to content

Commit

Permalink
Relax invalid url detection
Browse files Browse the repository at this point in the history
We accept any url that urlparse accepts, provided
it has a scheme.
  • Loading branch information
sbidoul committed Aug 22, 2020
1 parent 6c760c0 commit 1e3125f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 2 additions & 7 deletions packaging/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,10 @@ def __init__(self, requirement_string):
self.name = req.name
if req.url:
parsed_url = urlparse.urlparse(req.url)
if parsed_url.scheme and "+" in parsed_url.scheme:
# VCS url
pass
elif parsed_url.scheme == "file":
if parsed_url.scheme == "file":
if urlparse.urlunparse(parsed_url) != req.url:
raise InvalidRequirement("Invalid URL given")
elif not (parsed_url.scheme and parsed_url.netloc) or (
not parsed_url.scheme and not parsed_url.netloc
):
elif not parsed_url.scheme:
raise InvalidRequirement("Invalid URL: {0}".format(req.url))
self.url = req.url
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def test_url_and_marker(self):

def test_invalid_url(self):
with pytest.raises(InvalidRequirement) as e:
Requirement("name @ gopher:/foo/com")
Requirement("name @ /a/b")
assert "Invalid URL: " in str(e.value)
assert "gopher:/foo/com" in str(e.value)
assert "/a/b" in str(e.value)

def test_file_url(self):
req = Requirement("name @ file:///absolute/path")
Expand Down

0 comments on commit 1e3125f

Please sign in to comment.