Browse Source
部署配置里的词库默认不加载,校验等于空跑。把词库打进 home,命中即拒绝保存。 Co-authored-by: Cursor <cursoragent@cursor.com>along-test
6 changed files with 76 additions and 10 deletions
@ -0,0 +1,25 @@ |
|||
package wordfilter |
|||
|
|||
import ( |
|||
_ "embed" |
|||
"strings" |
|||
) |
|||
|
|||
// 内置词库随二进制打进 home。部署配置里的 WorldFile 默认全部注释,
|
|||
// 不内置的话改昵称时词树是空的,Validate 恒通过。
|
|||
//
|
|||
//go:embed wordfilter.txt
|
|||
var builtinWordDict string |
|||
|
|||
func (s *Sys) loadBuiltin() (int, error) { |
|||
n := 0 |
|||
for _, line := range strings.Split(builtinWordDict, "\n") { |
|||
line = strings.TrimSpace(line) |
|||
if line == "" { |
|||
continue |
|||
} |
|||
s.trie.Add(line) |
|||
n++ |
|||
} |
|||
return n, nil |
|||
} |
|||
Loading…
Reference in new issue