From a9ba9bbd455c402fa19f30a311ba88adb930c5c6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 15 Oct 2024 06:23:14 -0500 Subject: [PATCH] Avoid splitting the netloc for simple cases when constructing URL (#1277) --- yarl/_url.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/yarl/_url.py b/yarl/_url.py index 7125b936..470d18aa 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -273,7 +273,12 @@ def __new__( if not netloc: # netloc host = "" else: - username, password, host, port = cls._split_netloc(netloc) + if ":" in netloc or "@" in netloc or "[" in netloc: + # Complex netloc + username, password, host, port = cls._split_netloc(netloc) + else: + username = password = port = None + host = netloc if host is None: if scheme in SCHEME_REQUIRES_HOST: msg = (