From 39aaee8e02718fee53821630498fd3d084397242 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 20 Oct 2025 18:42:55 +0800 Subject: [PATCH] fix: handle empty message case in common.py and update username regex validation in user.py --- apps/common/utils/common.py | 5 ++++- apps/users/serializers/user.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index a4678cc84..d9418ec19 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -73,6 +73,8 @@ def encryption(message: str): :param message: :return: """ + if not message: # 处理空字符串情况 + return "***************" max_pre_len = 8 max_post_len = 4 message_len = len(message) @@ -335,5 +337,6 @@ def parse_image(content: str): def generate_uuid(tag: str): return str(uuid.uuid5(uuid.NAMESPACE_DNS, tag)) + def filter_workspace(query_list): - return [q for q in query_list if q.name!="workspace_id"] \ No newline at end of file + return [q for q in query_list if q.name != "workspace_id"] diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index c850c11bf..872ef06c8 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -143,7 +143,7 @@ class UserManageSerializer(serializers.Serializer): min_length=4, validators=[ validators.RegexValidator( - regex=re.compile("^.{4,20}$"), + regex=re.compile("^[^\u4e00-\u9fa5]{4,20}$"), message=_('Username must be 4-20 characters long') ) ]