mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-14 00:55:01 +03:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user