Fix clients group filter and search for non-ASCII capitals (#6685)

* Match non-ASCII capitals in the clients group filter and search

SQLite LOWER() only folds ASCII, so a group or search term with a Cyrillic,
Persian or other non-ASCII capital never matched after being lower-cased in
Go. Also compare the value as typed.

* Match lower, upper and title-case spellings for non-ASCII search and group filter
This commit is contained in:
kaveh
2026-10-03 02:52:28 +03:30
committed by GitHub
parent 5366eb0d29
commit 7802167443
2 changed files with 93 additions and 11 deletions
@@ -635,3 +635,36 @@ func TestListPagedEmptyPanel(t *testing.T) {
t.Fatal("groups = nil, want an empty list so the filter drawer renders")
}
}
// SQLite's LOWER() folds ASCII only, so non-ASCII capitals must still match.
func TestListPagedNonASCIICase(t *testing.T) {
svc, inboundSvc, settingSvc := setupPagingServices(t)
rec := model.ClientRecord{Email: "lima@x", Comment: "Привет", Group: "Тест", Enable: true}
if err := database.GetDB().Create(&rec).Error; err != nil {
t.Fatalf("create client: %v", err)
}
for name, params := range map[string]ClientPageParams{
"group": {PageSize: 50, Group: "Тест"},
"group other case": {PageSize: 50, Group: "ТЕСТ"},
"search": {PageSize: 50, Search: "Привет"},
"search lower case": {PageSize: 50, Search: "привет"},
"search upper case": {PageSize: 50, Search: "ПРИВЕТ"},
} {
resp, err := svc.ListPaged(inboundSvc, settingSvc, params)
if err != nil {
t.Fatalf("%s: ListPaged: %v", name, err)
}
if got := pagedEmails(resp.Items); !slices.Equal(got, []string{"lima@x"}) {
t.Fatalf("%s: emails = %v, want [lima@x]", name, got)
}
}
}
func TestCaseVariants(t *testing.T) {
if got, want := caseVariants("пРИвет"), []string{"привет", "пРИвет", "ПРИВЕТ", "Привет"}; !slices.Equal(got, want) {
t.Fatalf("caseVariants = %v, want %v", got, want)
}
if got := caseVariants("abc"); !slices.Equal(got, []string{"abc", "ABC", "Abc"}) {
t.Fatalf("ASCII variants = %v", got)
}
}