v1-0001-Another-unintentional-behavior-change-in-commit-e.patch
text/x-patch
Filename: v1-0001-Another-unintentional-behavior-change-in-commit-e.patch
Type: text/x-patch
Part: 0
Patch
Format: format-patch
Series: patch v1-0001
Subject: Another unintentional behavior change in commit e9931bfb75.
| File | + | − |
|---|---|---|
| src/backend/regex/regc_pg_locale.c | 19 | 5 |
From e8a68f42f5802d138ba04043b25b7d42862be29d Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Mon, 14 Apr 2025 11:34:11 -0700 Subject: [PATCH v1] Another unintentional behavior change in commit e9931bfb75. Reported-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/20250412123430.8c.nmisch@google.com --- src/backend/regex/regc_pg_locale.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/regex/regc_pg_locale.c b/src/backend/regex/regc_pg_locale.c index ed7411df83d..41b993ad773 100644 --- a/src/backend/regex/regc_pg_locale.c +++ b/src/backend/regex/regc_pg_locale.c @@ -21,9 +21,10 @@ #include "utils/pg_locale.h" /* - * To provide as much functionality as possible on a variety of platforms, - * without going so far as to implement everything from scratch, we use - * several implementation strategies depending on the situation: + * For the libc provider, to provide as much functionality as possible on a + * variety of platforms without going so far as to implement everything from + * scratch, we use several implementation strategies depending on the + * situation: * * 1. In C/POSIX collations, we use hard-wired code. We can't depend on * the <ctype.h> functions since those will obey LC_CTYPE. Note that these @@ -33,8 +34,9 @@ * * 2a. When working in UTF8 encoding, we use the <wctype.h> functions. * This assumes that every platform uses Unicode codepoints directly - * as the wchar_t representation of Unicode. On some platforms - * wchar_t is only 16 bits wide, so we have to punt for codepoints > 0xFFFF. + * as the wchar_t representation of Unicode. (XXX: This could be a problem + * for ICU in non-UTF8 encodings.) On some platforms wchar_t is only 16 bits + * wide, so we have to punt for codepoints > 0xFFFF. * * 2b. In all other encodings, we use the <ctype.h> functions for pg_wchar * values up to 255, and punt for values above that. This is 100% correct @@ -562,10 +564,16 @@ pg_wc_toupper(pg_wchar c) case PG_REGEX_STRATEGY_BUILTIN: return unicode_uppercase_simple(c); case PG_REGEX_STRATEGY_LIBC_WIDE: + /* force C behavior for ASCII characters, per comments above */ + if (pg_regex_locale->is_default && c <= (pg_wchar) 127) + return pg_ascii_toupper((unsigned char) c); if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF) return towupper_l((wint_t) c, pg_regex_locale->info.lt); /* FALL THRU */ case PG_REGEX_STRATEGY_LIBC_1BYTE: + /* force C behavior for ASCII characters, per comments above */ + if (pg_regex_locale->is_default && c <= (pg_wchar) 127) + return pg_ascii_toupper((unsigned char) c); if (c <= (pg_wchar) UCHAR_MAX) return toupper_l((unsigned char) c, pg_regex_locale->info.lt); return c; @@ -590,10 +598,16 @@ pg_wc_tolower(pg_wchar c) case PG_REGEX_STRATEGY_BUILTIN: return unicode_lowercase_simple(c); case PG_REGEX_STRATEGY_LIBC_WIDE: + /* force C behavior for ASCII characters, per comments above */ + if (pg_regex_locale->is_default && c <= (pg_wchar) 127) + return pg_ascii_tolower((unsigned char) c); if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF) return towlower_l((wint_t) c, pg_regex_locale->info.lt); /* FALL THRU */ case PG_REGEX_STRATEGY_LIBC_1BYTE: + /* force C behavior for ASCII characters, per comments above */ + if (pg_regex_locale->is_default && c <= (pg_wchar) 127) + return pg_ascii_tolower((unsigned char) c); if (c <= (pg_wchar) UCHAR_MAX) return tolower_l((unsigned char) c, pg_regex_locale->info.lt); return c; -- 2.34.1