From 726e7dfbd428735c68af426201a28b9931bc705c Mon Sep 17 00:00:00 2001 From: Akimio521 Date: Fri, 8 Nov 2024 14:31:08 +0800 Subject: [PATCH] feat(StringUtils): add url_eqote method --- app/utils/string.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/utils/string.py b/app/utils/string.py index 1960de63..0710fb98 100644 --- a/app/utils/string.py +++ b/app/utils/string.py @@ -805,3 +805,14 @@ 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)