From 9dfb42dea9c8e72d8fb72719d05c04b7833d1a33 Mon Sep 17 00:00:00 2001 From: Janne Pulkkinen Date: Thu, 29 Apr 2021 12:26:43 +0300 Subject: [PATCH] Use requests to quote URLs The previous fix to jamielennox#158 didn't match requests' own behavior and quoted a lot of additional characters, causing test breakage. Use `requests.utils.requote_uri` to quote the URL instead, which should ensure the behavior matches requests more closely. --- requests_mock/adapter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requests_mock/adapter.py b/requests_mock/adapter.py index 2ae5990..20f6598 100644 --- a/requests_mock/adapter.py +++ b/requests_mock/adapter.py @@ -13,6 +13,7 @@ import weakref from requests.adapters import BaseAdapter +from requests.utils import requote_uri import six from six.moves.urllib import parse as urlparse @@ -102,7 +103,7 @@ def __init__(self, method, url, responses, complete_qs, request_headers, url_parts = urlparse.urlparse(url) self._scheme = url_parts.scheme.lower() self._netloc = url_parts.netloc.lower() - self._path = urlparse.quote(url_parts.path or '/') + self._path = requote_uri(url_parts.path or '/') self._query = url_parts.query if not case_sensitive: