Skip to content

Commit

Permalink
Merge pull request #244 from sarugaku/bugfix/quote
Browse files Browse the repository at this point in the history
Don't encode/decode '+' in url auth part
  • Loading branch information
frostming authored May 29, 2020
2 parents 9d9ac1c + ac9b288 commit be76a67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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:
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("+", " "))
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

0 comments on commit be76a67

Please sign in to comment.