From 80629b9574e0344ed4e0e058f93ca79c7be768dd Mon Sep 17 00:00:00 2001 From: CaptainB Date: Thu, 9 Oct 2025 13:23:10 +0800 Subject: [PATCH] chore: enhance re_findall function to handle empty patterns and regex errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1062401 --user=刘瑞斌 【知识库】知识库文档分段的时候,如果使用的分段标识是文档中不存在的符号,点击生成预览会报错,希望这个报错提示词可以优化一下,方便识别 https://www.tapd.cn/62980211/s/1782047 --- apps/common/utils/split_model.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/common/utils/split_model.py b/apps/common/utils/split_model.py index de5ca86f3..eff9cc18f 100644 --- a/apps/common/utils/split_model.py +++ b/apps/common/utils/split_model.py @@ -169,7 +169,14 @@ def parse_level(text, pattern: str): def re_findall(pattern, text): - result = re.findall(pattern, text, flags=0) + if not pattern or not pattern.strip(): + return [] + + try: + result = re.findall(pattern, text, flags=0) + except re.error: + return [] + return list(filter(lambda r: r is not None and len(r) > 0, reduce(lambda x, y: [*x, *y], list( map(lambda row: [*(row if isinstance(row, tuple) else [row])], result)), [])))