From 8ca4ea0f3fc11086b5d3cf5aa1ae5224db99dab8 Mon Sep 17 00:00:00 2001 From: Dee Luo Date: Fri, 11 Apr 2025 15:43:40 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96qb=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=99=A8=E7=AB=AF=E5=8F=A3=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/string.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/utils/string.py b/app/utils/string.py index 527626f8..a786a813 100644 --- a/app/utils/string.py +++ b/app/utils/string.py @@ -642,13 +642,14 @@ class StringUtils: if len(parts) > 3: # 处理不希望包含多个冒号的情况(除了协议后的冒号) return None, None - # 不含端口地址 - domain = ":".join(parts[:-1]).rstrip('/') - # 端口号 - try: + elif len(parts) == 3: port = int(parts[-1]) - except ValueError: - # 端口号不是整数,返回 None 表示无效 + # 不含端口地址 + domain = ":".join(parts[:-1]).rstrip('/') + elif len(parts) == 2: + port = 443 if address.startswith("https") else 80 + domain = address + else: return None, None return domain, port