@@ -15,21 +15,32 @@ def __init__(self):
1515 self .customization = None
1616 self .custom_separator = None
1717
18+ @staticmethod
19+ def _normalize_customization (customization ):
20+ """
21+ 规范化自定义占位符配置,兼容历史字符串与列表两种保存格式。
22+ """
23+ if isinstance (customization , str ):
24+ customization = customization .replace ("\n " , ";" ).replace ("|" , ";" ).strip (";" ).split (";" )
25+ if not customization :
26+ return []
27+ return list (filter (None , customization ))
28+
1829 def match (self , title = None ):
1930 """
2031 :param title: 资源标题或文件名
2132 :return: 匹配结果
2233 """
2334 if not title :
2435 return ""
25- if not self . customization :
26- # 自定义占位符
27- customization = self .systemconfig .get (SystemConfigKey .Customization )
28- if not customization :
29- return ""
30- if isinstance ( customization , str ):
31- customization = customization . replace ( " \n " , ";" ). replace ( "|" , ";" ). strip ( ";" ). split ( ";" )
32- self .customization = "|" .join ([f"({ item } )" for item in customization ])
36+ # 自定义占位符需要跟随系统配置实时生效,避免单例缓存导致保存后仍沿用旧规则。
37+ customization = self . _normalize_customization (
38+ self .systemconfig .get (SystemConfigKey .Customization )
39+ )
40+ if not customization :
41+ self . customization = None
42+ return ""
43+ self .customization = "|" .join ([f"({ item } )" for item in customization ])
3344
3445 customization_re = re .compile (r"%s" % self .customization )
3546 # 处理重复多次的情况,保留先后顺序(按添加自定义占位符的顺序)
0 commit comments