diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-02-01 13:59:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 20:59:25 +0800 |
commit | bb5f859ec0f853383b85cb16b189fbacf7397551 (patch) | |
tree | 6ee234ba1f3c70bb6b55f0d7cc831ecf7f668110 /modules/util/util_test.go | |
parent | 7f2530e004c9908f9ee18b4060c8d4837a72f93b (diff) | |
download | gitea-bb5f859ec0f853383b85cb16b189fbacf7397551.tar.gz gitea-bb5f859ec0f853383b85cb16b189fbacf7397551.zip |
Fix non-ASCII search on database (#18437)
Use `ToASCIIUpper` for SQLite database on issues search, this because `UPPER(x)` on SQLite only transforms ASCII letters. Resolves #18429
Diffstat (limited to 'modules/util/util_test.go')
-rw-r--r-- | modules/util/util_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/util/util_test.go b/modules/util/util_test.go index b32cec23d9..0c2792a9cb 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -186,3 +186,37 @@ func Test_OptionalBool(t *testing.T) { assert.Equal(t, OptionalBoolTrue, OptionalBoolParse("t")) assert.Equal(t, OptionalBoolTrue, OptionalBoolParse("True")) } + +// Test case for any function which accepts and returns a single string. +type StringTest struct { + in, out string +} + +var upperTests = []StringTest{ + {"", ""}, + {"ONLYUPPER", "ONLYUPPER"}, + {"abc", "ABC"}, + {"AbC123", "ABC123"}, + {"azAZ09_", "AZAZ09_"}, + {"longStrinGwitHmixofsmaLLandcAps", "LONGSTRINGWITHMIXOFSMALLANDCAPS"}, + {"long\u0250string\u0250with\u0250nonascii\u2C6Fchars", "LONG\u0250STRING\u0250WITH\u0250NONASCII\u2C6FCHARS"}, + {"\u0250\u0250\u0250\u0250\u0250", "\u0250\u0250\u0250\u0250\u0250"}, + {"a\u0080\U0010FFFF", "A\u0080\U0010FFFF"}, + {"lél", "LéL"}, +} + +func TestToUpperASCII(t *testing.T) { + for _, tc := range upperTests { + assert.Equal(t, ToUpperASCII(tc.in), tc.out) + } +} + +func BenchmarkToUpper(b *testing.B) { + for _, tc := range upperTests { + b.Run(tc.in, func(b *testing.B) { + for i := 0; i < b.N; i++ { + ToUpperASCII(tc.in) + } + }) + } +} |