This commit is contained in:
jxxghp
2024-11-14 12:38:02 +08:00
parent 4b27404ee5
commit d6c6ee9b4e
3 changed files with 51 additions and 22 deletions

View File

@@ -805,14 +805,3 @@ class StringUtils:
:return: 如果elem有效非None且长度大于0返回True否则返回False
"""
return elem is not None and len(elem) > 0
@staticmethod
def url_eqote(s:str) -> str:
"""
将字符串编码为 URL 安全的格式
这将确保路径中的特殊字符(如空格、中文字符等)被正确编码,以便在 URL 中传输
:param s: 要编码的字符串
:return: 编码后的字符串
"""
return parse.quote(s)

View File

@@ -1,6 +1,7 @@
import mimetypes
from pathlib import Path
from typing import Optional, Union
from urllib import parse
from urllib.parse import parse_qs, urlencode, urljoin, urlparse, urlunparse
from app.log import logger
@@ -95,3 +96,14 @@ class UrlUtils:
except Exception as e:
logger.debug(f"Error get_mime_type: {e}")
return default_type
@staticmethod
def quote(s: str) -> str:
"""
将字符串编码为 URL 安全的格式
这将确保路径中的特殊字符(如空格、中文字符等)被正确编码,以便在 URL 中传输
:param s: 要编码的字符串
:return: 编码后的字符串
"""
return parse.quote(s)