From 8474bae2ba4cf8c6e91db800a441daffe22098ee Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Mon, 26 Oct 2026 15:11:21 -0700 Subject: [PATCH] Fix pg_iswcased() for some libc case mappings. Some C libraries, such as macOS libc, case-map characters that they do not classify as upper or lower. ILIKE index scans could then miss rows, because those characters stayed in the fixed prefix. Introduced in 630706ced0. 43a948b7b25 fixed similar issues, but missed this one. Author: shihao zhong Reviewed-by: Fujii Masao Reviewed-by: Chao Li Discussion: https://postgr.es/m/CAGRkXqS6pr-hG-g=K6RTdRw53SnMZWz3iXvh_wi8rqLSf972sA@mail.gmail.com Backpatch-through: 19 --- src/backend/utils/adt/pg_locale_libc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/pg_locale_libc.c b/src/backend/utils/adt/pg_locale_libc.c index 02c419aa62a..801f3dcafe0 100644 --- a/src/backend/utils/adt/pg_locale_libc.c +++ b/src/backend/utils/adt/pg_locale_libc.c @@ -328,10 +328,14 @@ wc_iscased_libc_utf8(pg_wchar wc, pg_locale_t locale) /* * For UTF8, pg_wchar is a codepoint and we assume we can pass it directly - * to iswupper_l()/iswlower_l(). + * to iswupper_l()/iswlower_l(). Some C libraries case-map characters + * that they do not classify as upper or lower, so also check the mapping, + * which is what ILIKE uses. */ return iswupper_l((wint_t) wc, locale->lt) || - iswlower_l((wint_t) wc, locale->lt); + iswlower_l((wint_t) wc, locale->lt) || + towupper_l((wint_t) wc, locale->lt) != (wint_t) wc || + towlower_l((wint_t) wc, locale->lt) != (wint_t) wc; } static pg_wchar