other fixes
This commit is contained in:
11 files changed
+339
-10
No files matched your search
@@ -7,7 +7,7 @@ import urllib.parse
|
||||
|
||||
|
||||
def _qs(query: str) -> dict:
|
||||
return dict(urllib.parse.parse_qsl(query))
|
||||
return dict(urllib.parse.parse_qsl(query, keep_blank_values=True))
|
||||
|
||||
|
||||
def _split_host_port(hostpart: str) -> tuple[str, str]:
|
||||
@@ -23,7 +23,7 @@ def _parse_url_parts(url: str, scheme: str) -> tuple[str, str, str, dict]:
|
||||
rest = url[len(f"{scheme}://") :]
|
||||
rest, _, _ = rest.partition("#")
|
||||
if "@" in rest:
|
||||
userinfo, _, rest = rest.partition("@")
|
||||
userinfo, _, rest = rest.rpartition("@")
|
||||
else:
|
||||
userinfo = ""
|
||||
hostpart, _, query = rest.partition("?")
|
||||
@@ -119,6 +119,9 @@ def parse_vless(url: str, tag: str) -> dict:
|
||||
|
||||
def parse_vmess(url: str, tag: str) -> dict:
|
||||
b64 = url[len("vmess://") :]
|
||||
b64, _, _ = b64.partition("#")
|
||||
b64, _, _ = b64.partition("?")
|
||||
b64 = urllib.parse.unquote(b64)
|
||||
pad = "=" * (-len(b64) % 4)
|
||||
try:
|
||||
data = json.loads(base64.b64decode(b64 + pad))
|
||||
|
||||
@@ -39,6 +39,19 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["transport"]["type"], "ws")
|
||||
self.assertEqual(ob["tls"]["server_name"], "cdn.example.com")
|
||||
|
||||
def test_vmess_with_external_remark(self):
|
||||
payload = {
|
||||
"add": "vmess.example.com",
|
||||
"port": "443",
|
||||
"id": "00000000-0000-0000-0000-000000000000",
|
||||
"aid": "0",
|
||||
"scy": "auto",
|
||||
}
|
||||
encoded = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
|
||||
ob = run_parser(f"vmess://{encoded}#Subscription Remark")
|
||||
self.assertEqual(ob["type"], "vmess")
|
||||
self.assertEqual(ob["server"], "vmess.example.com")
|
||||
|
||||
def test_trojan(self):
|
||||
ob = run_parser("trojan://secret@example.com:443?sni=tls.example.com&fp=chrome")
|
||||
self.assertEqual(ob["type"], "trojan")
|
||||
@@ -109,6 +122,12 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["version"], "5")
|
||||
self.assertEqual(ob["username"], "user")
|
||||
|
||||
def test_proxy_userinfo_allows_at_in_password(self):
|
||||
ob = run_parser("socks5://user:p@ss@example.com:1080")
|
||||
self.assertEqual(ob["username"], "user")
|
||||
self.assertEqual(ob["password"], "p@ss")
|
||||
self.assertEqual(ob["server"], "example.com")
|
||||
|
||||
def test_https_proxy(self):
|
||||
ob = run_parser("https://proxy.example.com:8443")
|
||||
self.assertEqual(ob["type"], "http")
|
||||
|
||||
Reference in new issue
Block a user