From c0c787f7ed93e8c775c236b9f90ce44a8e7a0494 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 7 Jun 2024 08:01:23 +0800 Subject: [PATCH] fix --- app/utils/string.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/utils/string.py b/app/utils/string.py index 77d0238e..cc0bbac4 100644 --- a/app/utils/string.py +++ b/app/utils/string.py @@ -609,23 +609,21 @@ class StringUtils: """ if not address: return None, None + # 去掉末尾的/ + address = address.rstrip("/") if prefix and not address.startswith("http"): # 如果需要包含协议前缀,但地址不包含协议前缀,则添加 address = "http://" + address elif not prefix and address.startswith("http"): # 如果不需要包含协议前缀,但地址包含协议前缀,则去掉 address = address.split("://")[-1] - # 去掉末尾的/ - address = address.rstrip("/") # 拆分域名和端口号 parts = address.split(":") if len(parts) > 3: # 处理不希望包含多个冒号的情况(除了协议后的冒号) return None, None # 不含端口地址 - domain = ":".join(parts[:-1]) - if domain.endswith("/"): - domain = domain[:-1] + domain = ":".join(parts[:-1]).rstrip('/') # 端口号 try: port = int(parts[-1])