Replacing blacklist with blocklist (#15082)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fea28821e3
Коммит
30bd506e76
@@ -659,12 +659,12 @@ func AsStringBoolMap(list []string) map[string]bool {
|
|||||||
|
|
||||||
// SanitizeUnicode will remove undesirable Unicode characters from a string.
|
// SanitizeUnicode will remove undesirable Unicode characters from a string.
|
||||||
func SanitizeUnicode(s string) string {
|
func SanitizeUnicode(s string) string {
|
||||||
return strings.Map(filterBlacklist, s)
|
return strings.Map(filterBlocklist, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterBlacklist returns `r` if it is not in the blacklist, otherwise drop (-1).
|
// filterBlocklist returns `r` if it is not in the blocklist, otherwise drop (-1).
|
||||||
// Blacklist is taken from https://www.w3.org/TR/unicode-xml/#Charlist
|
// Blocklist is taken from https://www.w3.org/TR/unicode-xml/#Charlist
|
||||||
func filterBlacklist(r rune) rune {
|
func filterBlocklist(r rune) rune {
|
||||||
const drop = -1
|
const drop = -1
|
||||||
switch r {
|
switch r {
|
||||||
case '\u0340', '\u0341': // clones of grave and acute; deprecated in Unicode
|
case '\u0340', '\u0341': // clones of grave and acute; deprecated in Unicode
|
||||||
|
|||||||
@@ -766,8 +766,8 @@ func TestSanitizeUnicode(t *testing.T) {
|
|||||||
{name: "ascii only", arg: "Hello There", want: "Hello There"},
|
{name: "ascii only", arg: "Hello There", want: "Hello There"},
|
||||||
{name: "allowed unicode", arg: "Ādam likes Iñtërnâtiônàližætiøn", want: "Ādam likes Iñtërnâtiônàližætiøn"},
|
{name: "allowed unicode", arg: "Ādam likes Iñtërnâtiônàližætiøn", want: "Ādam likes Iñtërnâtiônàližætiøn"},
|
||||||
{name: "allowed unicode escaped", arg: "\u00eaI like hats\u00e2", want: "êI like hatsâ"},
|
{name: "allowed unicode escaped", arg: "\u00eaI like hats\u00e2", want: "êI like hatsâ"},
|
||||||
{name: "blacklist char, don't reverse string", arg: "\u202E2resu", want: "2resu"},
|
{name: "blocklist char, don't reverse string", arg: "\u202E2resu", want: "2resu"},
|
||||||
{name: "blacklist chars, scoping musical notation", arg: musicArg, want: musicWant},
|
{name: "blocklist chars, scoping musical notation", arg: musicArg, want: musicWant},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user