MM-23489 Fix poor Unicode handling in display names (#14214)
Filter blacklisted Unicode characters from: user: first name, last name, nickname, bot description, username team: name, display name, description, company name channel: name, display name
Этот коммит содержится в:
@@ -647,3 +647,48 @@ func AsStringBoolMap(list []string) map[string]bool {
|
||||
}
|
||||
return listMap
|
||||
}
|
||||
|
||||
// SanitizeUnicode will remove undesirable Unicode characters from a string.
|
||||
func SanitizeUnicode(s string) string {
|
||||
return strings.Map(filterBlacklist, s)
|
||||
}
|
||||
|
||||
// filterBlacklist returns `r` if it is not in the blacklist, otherwise drop (-1).
|
||||
// Blacklist is taken from https://www.w3.org/TR/unicode-xml/#Charlist
|
||||
func filterBlacklist(r rune) rune {
|
||||
const drop = -1
|
||||
switch r {
|
||||
case '\u0340', '\u0341': // clones of grave and acute; deprecated in Unicode
|
||||
return drop
|
||||
case '\u17A3', '\u17D3': // obsolete characters for Khmer; deprecated in Unicode
|
||||
return drop
|
||||
case '\u2028', '\u2029': // line and paragraph separator
|
||||
return drop
|
||||
case '\u202A', '\u202B', '\u202C', '\u202D', '\u202E': // BIDI embedding controls
|
||||
return drop
|
||||
case '\u206A', '\u206B': // activate/inhibit symmetric swapping; deprecated in Unicode
|
||||
return drop
|
||||
case '\u206C', '\u206D': // activate/inhibit Arabic form shaping; deprecated in Unicode
|
||||
return drop
|
||||
case '\u206E', '\u206F': // activate/inhibit national digit shapes; deprecated in Unicode
|
||||
return drop
|
||||
case '\uFFF9', '\uFFFA', '\uFFFB': // interlinear annotation characters
|
||||
return drop
|
||||
case '\uFEFF': // byte order mark
|
||||
return drop
|
||||
case '\uFFFC': // object replacement character
|
||||
return drop
|
||||
}
|
||||
|
||||
// Scoping for musical notation
|
||||
if r >= 0x0001D173 && r <= 0x0001D17A {
|
||||
return drop
|
||||
}
|
||||
|
||||
// Language tag code points
|
||||
if r >= 0x000E0000 && r <= 0x000E007F {
|
||||
return drop
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user