]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix unintentional behavior change from 5a38104b36.
authorJeff Davis <jdavis@postgresql.org>
Wed, 8 Jul 2026 01:04:33 +0000 (18:04 -0700)
committerJeff Davis <jdavis@postgresql.org>
Wed, 8 Jul 2026 01:04:33 +0000 (18:04 -0700)
Reported-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/20260630012919.78@rfd.leadboat.com
Backpatch-through: 19

src/backend/utils/adt/like.c
src/test/regress/expected/collate.utf8.out
src/test/regress/sql/collate.utf8.sql

index 350bc07f210e1ab90ca9ffad13c77f96cbf2981e..64147bc5b5ccbb6ce16091b5ad995a16fcbf04df 100644 (file)
@@ -191,12 +191,14 @@ Generic_Text_IC_like(text *str, text *pat, Oid collation)
 
        /*
         * For efficiency reasons, in the C locale we don't call lower() on the
-        * pattern and text, but instead lowercase each character lazily.
+        * pattern and text, but instead lowercase each character lazily. This
+        * only works for single-byte encodings, otherwise "_" may incorrectly
+        * match an incomplete byte sequence.
         *
         * XXX: use casefolding instead?
         */
 
-       if (locale->ctype_is_c)
+       if (locale->ctype_is_c && pg_database_encoding_max_length() == 1)
        {
                p = VARDATA_ANY(pat);
                plen = VARSIZE_ANY_EXHDR(pat);
index 99fdc111fa4c63af7ea6a76d2174dd41da262fec..cdd1a37ba18c70bda9c2fa428e939b27de654530 100644 (file)
@@ -34,6 +34,13 @@ SELECT U&'\00C1\00E1' !~ '[[:alpha:]]' COLLATE regress_builtin_c;
 (1 row)
 
 DROP COLLATION regress_builtin_c;
+-- a '_' matches a multibyte character
+SELECT 'café' ILIKE 'caf_' COLLATE "C";
+ ?column? 
+----------
+ t
+(1 row)
+
 --
 -- Test PG_C_UTF8
 --
index 22aecee3a60dbc4a6c3ad605c140de90620db033..52cf068dd0ca2e718296ba5779d8c1117ccceed3 100644 (file)
@@ -26,6 +26,9 @@ SELECT U&'\00C1\00E1' !~ '[[:alpha:]]' COLLATE regress_builtin_c;
 
 DROP COLLATION regress_builtin_c;
 
+-- a '_' matches a multibyte character
+SELECT 'café' ILIKE 'caf_' COLLATE "C";
+
 --
 -- Test PG_C_UTF8
 --