postgresql/src/backend
Michael Paquier b3e99115e4 Fix conversion of SIMILAR TO regexes for character classes
The code that translates SIMILAR TO pattern matching expressions to
POSIX-style regular expressions did not consider that square brackets
can be nested.  For example, in an expression like [[:alpha:]%_], the
logic replaced the placeholders '_' and '%' but it should not.

This commit fixes the conversion logic by tracking the nesting level of
square brackets marking character class areas, while considering that
in expressions like []] or [^]] the first closing square bracket is a
regular character.  Multiple tests are added to show how the conversions
should or should not apply applied while in a character class area, with
specific cases added for all the characters converted outside character
classes like an opening parenthesis '(', dollar sign '$', etc.

Author: Laurenz Albe <laurenz.albe@cybertec.at>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/16ab039d1af455652bdf4173402ddda145f2c73b.camel@cybertec.at
Backpatch-through: 13
2025-05-28 08:59:25 +09:00
..
access Fix incorrect WAL description for PREPARE TRANSACTION record. 2025-05-21 11:56:39 +09:00
backup Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:29:40 +10:30
bootstrap Process session_preload_libraries within InitPostgres's transaction. 2022-07-25 10:27:43 -04:00
catalog Repair misbehavior with duplicate entries in FK SET column lists. 2025-04-04 20:11:48 -04:00
commands Handle self-referencing FKs correctly in partitioned tables 2025-05-02 21:25:50 +02:00
executor Fix failure for generated column with a not-null domain constraint. 2025-04-15 12:08:34 -04:00
foreign Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:25 -07:00
jit Fix NULLIF()'s handling of read-write expanded objects. 2024-11-25 18:09:10 -05:00
lib Accommodate very large dshash tables. 2024-12-17 15:24:45 -06:00
libpq Fix regression in TLS session ticket disabling 2024-08-19 12:55:11 +02:00
main Fix elog(FATAL) before PostmasterMain() or just after fork(). 2024-12-10 13:52:02 -08:00
nodes Build whole-row Vars the same way during parsing and planning. 2025-03-12 11:47:19 -04:00
optimizer Fix failure for generated column with a not-null domain constraint. 2025-04-15 12:08:34 -04:00
parser Fix Assert failure in XMLTABLE parser 2025-05-15 17:26:13 +09:00
partitioning Fix creation of partition descriptor during concurrent detach+drop 2024-08-12 18:17:56 -04:00
po Translation updates 2025-05-05 12:20:37 +02:00
port Close socket in case of errors in setting non-blocking 2024-01-17 11:24:11 +01:00
postmaster Fix per-relation memory leakage in autovacuum. 2025-05-23 14:43:44 -04:00
regex Fix recently-exposed portability issue in regex optimization. 2024-11-17 14:14:06 -05:00
replication Don't retreat slot's confirmed_flush LSN. 2025-05-19 11:28:19 +05:30
rewrite Repair commits 317aba70e et al for -DWRITE_READ_PARSE_PLAN_TREES. 2025-03-13 12:13:07 -04:00
snowball Avoid null pointer dereference crash after OOM in Snowball stemmers. 2025-02-18 21:23:59 -05:00
statistics Fix incorrectly reported stats kind in "can't happen" ERROR 2024-03-05 16:18:19 +13:00
storage doc: Correct description of values used in FSM for indexes 2025-03-27 10:20:48 +09:00
tcop Repair commits 317aba70e et al for -DWRITE_READ_PARSE_PLAN_TREES. 2025-03-13 12:13:07 -04:00
tsearch Clear errno before calling strtol() in spell.c. 2025-03-08 11:24:52 -05:00
utils Fix conversion of SIMILAR TO regexes for character classes 2025-05-28 08:59:25 +09:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Move basebackup code to new directory src/backend/backup 2022-08-10 14:03:09 -04:00
nls.mk Translation updates 2023-11-06 13:16:22 +01:00