diff options
author | Richard <nyuszika7h@gmail.com> | 2021-07-16 05:19:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-16 03:19:14 +0000 |
commit | 2cd237e5cf5e899a4b3e285a48c23a77564832e1 (patch) | |
tree | a88a7f977cdb733a1a0b164f35b446201f65f752 | |
parent | 426ed15429e103e78cb76982d46c41a52b7947ff (diff) | |
download | websocket-client-2cd237e5cf5e899a4b3e285a48c23a77564832e1.tar.gz |
Unquote username and password in proxy from environment (#723)
This fixes e.g. credentials containing a `@` escaped as `%40`.
Closes #722.
-rw-r--r-- | websocket/_url.py | 4 | ||||
-rw-r--r-- | websocket/tests/test_url.py | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/websocket/_url.py b/websocket/_url.py index f681ebf..0867911 100644 --- a/websocket/_url.py +++ b/websocket/_url.py @@ -26,7 +26,7 @@ import os import socket import struct -from urllib.parse import urlparse +from urllib.parse import unquote, urlparse __all__ = ["parse_url", "get_proxy_info"] @@ -171,7 +171,7 @@ def get_proxy_info( value = os.environ.get(key, os.environ.get(key.upper(), "")).replace(" ", "") if value: proxy = urlparse(value) - auth = (proxy.username, proxy.password) if proxy.username else None + auth = (unquote(proxy.username), unquote(proxy.password)) if proxy.username else None return proxy.hostname, proxy.port, auth return None, 0, None diff --git a/websocket/tests/test_url.py b/websocket/tests/test_url.py index a33e934..34a3594 100644 --- a/websocket/tests/test_url.py +++ b/websocket/tests/test_url.py @@ -277,6 +277,10 @@ class ProxyInfoTest(unittest.TestCase): os.environ["https_proxy"] = "http://a:b@localhost2:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", 3128, ("a", "b"))) + os.environ["http_proxy"] = "http://john%40example.com:P%40SSWORD@localhost:3128/" + os.environ["https_proxy"] = "http://john%40example.com:P%40SSWORD@localhost2:3128/" + self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", 3128, ("john@example.com", "P@SSWORD"))) + os.environ["http_proxy"] = "http://a:b@localhost/" os.environ["https_proxy"] = "http://a:b@localhost2/" os.environ["no_proxy"] = "example1.com,example2.com" |