Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't encode/decode '+' in url auth part #244

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/requirementslib/models/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import attr
import pip_shims.shims
from orderedmultidict import omdict
from six.moves.urllib.parse import quote_plus, unquote_plus
from six.moves.urllib.parse import quote, unquote_plus, unquote as url_unquote
from urllib3 import util as urllib3_util
from urllib3.util import parse_url as urllib3_parse
from urllib3.util.url import Url
Expand Down Expand Up @@ -42,8 +42,8 @@ def _get_parsed_url(url):
auth, _, url = url.rpartition("@")
url = "{scheme}://{url}".format(scheme=scheme, url=url)
parsed = urllib3_parse(url)._replace(auth=auth)
if parsed.auth and unquote_plus(parsed.auth) != parsed.auth:
techalchemy marked this conversation as resolved.
Show resolved Hide resolved
return parsed._replace(auth=unquote_plus(parsed.auth))
if parsed.auth:
return parsed._replace(auth=url_unquote(parsed.auth))
return parsed


Expand Down Expand Up @@ -110,7 +110,7 @@ def _parse_query(self):
subdirectory = self.subdirectory if self.subdirectory else None
for q in queries:
key, _, val = q.partition("=")
val = unquote_plus(val.replace("+", " "))
val = unquote_plus(val)
if key == "subdirectory" and not subdirectory:
subdirectory = val
else:
Expand All @@ -132,7 +132,7 @@ def _parse_fragment(self):
extras = self.extras
for q in fragments:
key, _, val = q.partition("=")
val = unquote_plus(val.replace("+", " "))
Copy link
Member Author

Choose a reason for hiding this comment

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

This replacement is not necessary as unquote_plus will handle plus characters.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, i wasn't thinking too hard at the time probably...

val = unquote_plus(val)
fragment_items[key] = val
if key == "egg":
from .utils import parse_extras
Expand All @@ -158,10 +158,10 @@ def _parse_auth(self):
username_is_quoted, password_is_quoted = False, False
quoted_username, quoted_password = "", ""
if password:
quoted_password = quote_plus(password)
quoted_password = quote(password)
password_is_quoted = quoted_password != password
if username:
quoted_username = quote_plus(username)
quoted_username = quote(username)
username_is_quoted = quoted_username != username
return attr.evolve(
self,
Expand All @@ -176,14 +176,14 @@ def get_password(self, unquote=False, include_token=True):
# type: (bool, bool) -> str
password = self.password if self.password else ""
if password and unquote and self._password_is_quoted:
password = unquote_plus(password)
password = url_unquote(password)
return password

def get_username(self, unquote=False):
# type: (bool) -> str
username = self.username if self.username else ""
if username and unquote and self._username_is_quoted:
username = unquote_plus(username)
username = url_unquote(username)
return username

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

from hypothesis import assume, given, strategies as st
from six.moves.urllib_parse import quote_plus, unquote_plus, urlsplit, urlunsplit
from six.moves.urllib_parse import quote_plus, urlsplit, urlunsplit
from vistir.compat import Path

from requirementslib.models.url import URI
Expand Down