TrimBlankChar添加对于隐藏字符的过滤

This commit is contained in:
gazebo
2019-12-27 11:30:41 +08:00
parent 7ce628a4ec
commit fb60ff6576
2 changed files with 16 additions and 5 deletions

View File

@@ -242,7 +242,7 @@ func FilterEmoji(content string) string {
}
func TrimBlankChar(str string) string {
return strings.Trim(str, "\n\r\t ")
return strings.Trim(str, "\u202C\n\r\t ")
}
func RemoveGeneralMapKeys(obj map[string]interface{}, keys ...string) map[string]interface{} {

View File

@@ -191,11 +191,22 @@ func TestRemoveGeneralMapKeys(t *testing.T) {
}
func TestTrimBlanChar(t *testing.T) {
str := `
for _, strList := range [][]string{
[]string{
"大小21",
`
大小21
`
if TrimBlankChar(str) != "大小21" {
t.Fatal("TrimBlanChar doesn't work")
`,
},
[]string{
"13518183468",
"13518183468", // 末尾有一个隐藏字符
},
} {
t.Logf("%d,%d", len(strList[0]), len(strList[1]))
if TrimBlankChar(strList[1]) != strList[0] {
t.Fatal("TrimBlanChar doesn't work")
}
}
}