@@ -3,6 +3,11 @@ package main
3
3
import (
4
4
"net/http"
5
5
"strings"
6
+ "unicode"
7
+
8
+ "golang.org/x/text/runes"
9
+ "golang.org/x/text/transform"
10
+ "golang.org/x/text/unicode/norm"
6
11
7
12
"github.com/mattermost/mattermost-server/model"
8
13
"github.com/mattermost/mattermost-server/plugin"
@@ -23,7 +28,7 @@ func main() {
23
28
func (p * Plugin ) OnActivate () error {
24
29
p .badWords = make (map [string ]bool , len (badWords ))
25
30
for _ , word := range badWords {
26
- p .badWords [strings .ToLower (word )] = true
31
+ p .badWords [strings .ToLower (removeAccents ( word ) )] = true
27
32
}
28
33
29
34
return nil
@@ -37,7 +42,7 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req
37
42
}
38
43
39
44
func (p * Plugin ) WordIsBad (word string ) bool {
40
- _ , ok := p .badWords [strings .ToLower (word )]
45
+ _ , ok := p .badWords [strings .ToLower (removeAccents ( word ) )]
41
46
return ok
42
47
}
43
48
@@ -64,3 +69,13 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode
64
69
func (p * Plugin ) MessageWillBeUpdated (c * plugin.Context , newPost * model.Post , _ * model.Post ) (* model.Post , string ) {
65
70
return p .FilterPost (newPost )
66
71
}
72
+
73
+ func removeAccents (s string ) string {
74
+ t := transform .Chain (norm .NFD , runes .Remove (runes .In (unicode .Mn )), norm .NFC )
75
+ output , _ , e := transform .String (t , s )
76
+ if e != nil {
77
+ return s
78
+ }
79
+
80
+ return output
81
+ }
0 commit comments