diff --git a/pkg/providers/check-issue/event.go b/pkg/providers/check-issue/event.go
index b6c1748..e0cef60 100644
--- a/pkg/providers/check-issue/event.go
+++ b/pkg/providers/check-issue/event.go
@@ -5,7 +5,7 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
- "strings"
+ "regexp"
"unicode"
"github.com/google/go-github/v32/github"
@@ -78,7 +78,9 @@ func (c *Check) IsIncludeChinese(str string) bool {
// filter
str = filterImg(str)
// filter []
- str = filterBracket(str)
+ str = filterSquareBracket(str)
+ // filter ``` ```
+ str = filterBackQuote(str)
var count int
for _, v := range str {
if unicode.Is(unicode.Han, v) {
@@ -90,26 +92,20 @@ func (c *Check) IsIncludeChinese(str string) bool {
}
func filterImg(str string) string {
- for {
- startIndex := strings.Index(str, "")
- str = str[0:startIndex] + str[endIndex+1:]
- }
+ re := regexp.MustCompile(``)
+ str = re.ReplaceAllString(str, "")
return str
}
-func filterBracket(str string) string {
- for {
- startIndex := strings.Index(str, "[")
- if startIndex == -1 {
- break
- }
- endIndex := startIndex + strings.Index(str[startIndex:], "]")
- str = str[0:startIndex] + str[endIndex+1:]
- }
+func filterSquareBracket(str string) string {
+ re := regexp.MustCompile(`\[.*?\]`)
+ str = re.ReplaceAllString(str, "")
+ return str
+}
+
+func filterBackQuote(str string) string {
+ re := regexp.MustCompile("\\`\\`\\`.*?\\`\\`\\`")
+ str = re.ReplaceAllString(str, "")
return str
}
diff --git a/pkg/providers/check-issue/event_test.go b/pkg/providers/check-issue/event_test.go
index 6606918..64b80d2 100644
--- a/pkg/providers/check-issue/event_test.go
+++ b/pkg/providers/check-issue/event_test.go
@@ -8,11 +8,25 @@ import (
func TestFilterImg(t *testing.T) {
//str1 := "sfdf"
str := "352452aaaa 中文 sss<><><><> <><><>"
+ fmt.Println(str)
fmt.Println(filterImg(str))
}
-func TestFilterBractet(t *testing.T) {
+func TestFilterSquareBracket(t *testing.T) {
//str := "[中文]2525[]"
str := "## Error Report\\r\\n\\r\\n**This repository is ONLY used to solve issues related to DOCS.\\r\\nFor other issues (related to TiDB, PD, etc), please move to [other repositories](https://github.com/pingcap/).**\\r\\n\\r\\nPlease answer the following questions before submitting your issue. Thanks!\\r\\n\\r\\n1. What is the URL/path of the document related to this issue?\\r\\n\\r\\nhttps://docs.pingcap.com/zh/tidb/dev/privilege-management\\r\\n\\r\\n2. How would you like to improve it?\\r\\n\\r\\ndelete grand in the table\\r\\n\\r\\n![企业微信截图_e7ea7242-875c-443f-9661-39bec203c1ee](https://user-images.githubusercontent.com/53471087/106870333-f228e680-670b-11eb-9048-14c1d5a729e7.png)\\r\\n\\r\\n\\r\\n\\r\\n\\r\\n"
- fmt.Println(filterBracket(str))
+ fmt.Println(str)
+ fmt.Println(filterSquareBracket(str))
+}
+
+func TestFilterBackQuote(t *testing.T) {
+ str := "```ǎ傦眢否畬傮Ȕ炏芭裪```"
+ fmt.Println(str)
+ fmt.Println(filterBackQuote(str))
+}
+
+func TestAll(t *testing.T) {
+ str := " <> [] [<>] () (\"\") ``` ``` "
+ fmt.Println(str)
+ fmt.Println(filterImg(filterSquareBracket(filterBackQuote(str))))
}