-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
package utils | ||
|
||
import ( | ||
"treehole_next/config" | ||
"treehole_next/data" | ||
) | ||
|
||
func IsSensitive(content string) bool { | ||
if !config.Config.OpenSensitiveCheck { | ||
return false | ||
} | ||
|
||
if data.SensitiveWordFilter != nil { | ||
in, _ := data.SensitiveWordFilter.FindIn(content) | ||
return in | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/importcjj/sensitive" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"treehole_next/config" | ||
"treehole_next/data" | ||
) | ||
|
||
func TestIsSensitive(t *testing.T) { | ||
data.SensitiveWordFilter = sensitive.New() | ||
data.SensitiveWordFilter.AddWord("天气", "小明", "123") | ||
config.Config.OpenSensitiveCheck = true | ||
type args struct { | ||
content string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "test1", | ||
args: args{content: "今天天气真好"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "test2", | ||
args: args{content: "昨天吃了什么"}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, IsSensitive(tt.args.content), "IsSensitive(%v)", tt.args.content) | ||
}) | ||
} | ||
} |