From 0ee245f919dd45aabc8be245a5f8aa76661909d9 Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Sat, 22 Aug 2026 17:47:24 -0400
Subject: [PATCH 2/4] Pin two ctype-dependent test_regex_utf8 cases to a fixed
 collation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

test_regex_utf8 decides whether to run by looking at the database
encoding alone, but two of its cases, [[:graph:]] and [[:print:]] over
E'xᔀሷ', depend on the ctype as well.  In a database with encoding
UTF8 and locale C they match just the x, because isgraph() and isprint()
are false for anything outside ASCII, and the file fails.  That is the
right answer for such a database; the test was wrong to assume there
could only be one.

Fix by giving the two cases an explicit collation, so that they exercise
a fixed Unicode ctype instead of whatever the database happened to be
initialized with.  test_regex() already passes its input collation down
to the regex compiler.  The expected results are unchanged; only the
echoed queries differ.

Backpatch to 17, where the builtin pg_c_utf8 collation appeared.
---
 src/test/modules/test_regex/expected/test_regex_utf8.out | 6 ++++--
 src/test/modules/test_regex/sql/test_regex_utf8.sql      | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/test/modules/test_regex/expected/test_regex_utf8.out b/src/test/modules/test_regex/expected/test_regex_utf8.out
index 329780ef400..177eb1cacec 100644
--- a/src/test/modules/test_regex/expected/test_regex_utf8.out
+++ b/src/test/modules/test_regex/expected/test_regex_utf8.out
@@ -147,7 +147,9 @@ select * from test_regex('[[:digit:]]+',  E'x9\u1500\u1237', 'L');
  {9}
 (2 rows)
 
-select * from test_regex('[[:graph:]]+',  E'x\u1500\u1237', 'L');
+-- graph and print depend on the ctype and not just the encoding, so pin them
+-- to a Unicode-aware collation rather than the database's
+select * from test_regex('[[:graph:]]+',  E'x\u1500\u1237' COLLATE pg_c_utf8, 'L');
    test_regex    
 -----------------
  {0,REG_ULOCALE}
@@ -161,7 +163,7 @@ select * from test_regex('[[:lower:]]+',  E'x\u1500\u1237', 'L');
  {x}
 (2 rows)
 
-select * from test_regex('[[:print:]]+',  E'x\u1500\u1237', 'L');
+select * from test_regex('[[:print:]]+',  E'x\u1500\u1237' COLLATE pg_c_utf8, 'L');
    test_regex    
 -----------------
  {0,REG_ULOCALE}
diff --git a/src/test/modules/test_regex/sql/test_regex_utf8.sql b/src/test/modules/test_regex/sql/test_regex_utf8.sql
index 1f69f105fd7..d00599b3490 100644
--- a/src/test/modules/test_regex/sql/test_regex_utf8.sql
+++ b/src/test/modules/test_regex/sql/test_regex_utf8.sql
@@ -66,9 +66,11 @@ select * from test_regex('[[:ascii:]]+',  E'x\u1500\u1237', 'L');
 select * from test_regex('[[:blank:]]+',  E'x \t\u1500\u1237', 'L');
 select * from test_regex('[[:cntrl:]]+',  E'x\u1500\u1237', 'L');
 select * from test_regex('[[:digit:]]+',  E'x9\u1500\u1237', 'L');
-select * from test_regex('[[:graph:]]+',  E'x\u1500\u1237', 'L');
+-- graph and print depend on the ctype and not just the encoding, so pin them
+-- to a Unicode-aware collation rather than the database's
+select * from test_regex('[[:graph:]]+',  E'x\u1500\u1237' COLLATE pg_c_utf8, 'L');
 select * from test_regex('[[:lower:]]+',  E'x\u1500\u1237', 'L');
-select * from test_regex('[[:print:]]+',  E'x\u1500\u1237', 'L');
+select * from test_regex('[[:print:]]+',  E'x\u1500\u1237' COLLATE pg_c_utf8, 'L');
 select * from test_regex('[[:punct:]]+',  E'x.\u1500\u1237', 'L');
 select * from test_regex('[[:space:]]+',  E'x \t\u1500\u1237', 'L');
 select * from test_regex('[[:upper:]]+',  E'xX\u1500\u1237', 'L');
-- 
2.43.0

