pgsql: Amend recent fix for SIMILAR TO regex conversion.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Amend recent fix for SIMILAR TO regex conversion.
Date: 2025-09-13 20:56:15
Message-ID: E1uxXI7-000Ywd-0V@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Amend recent fix for SIMILAR TO regex conversion.

Commit e3ffc3e91 fixed the translation of character classes in
SIMILAR TO regular expressions. Unfortunately the fix broke a corner
case: if there is an escape character right after the opening bracket
(for example in "[\q]"), a closing bracket right after the escape
sequence would not be seen as closing the character class.

There were two more oversights: a backslash or a nested opening bracket
right at the beginning of a character class should remove the special
meaning from any following caret or closing bracket.

This bug suggests that this code needs to be more readable, so also
rename the variables "charclass_depth" and "charclass_start" to
something more meaningful, rewrite an "if" cascade to be more
consistent, and improve the commentary.

Reported-by: Dominique Devienne <ddevienne(at)gmail(dot)com>
Reported-by: Stephan Springl <springl-psql(at)bfw-online(dot)de>
Author: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/CAFCRh-8NwJd0jq6P=R3qhHyqU7hw0BTor3W0SvUcii24et+zAw@mail.gmail.com
Backpatch-through: 13

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/281ad4ed11d235cccad78fcbf7d807c615e1c0e8

Modified Files
--------------
src/backend/utils/adt/regexp.c | 97 +++++++++++++++++++++++++----------
src/test/regress/expected/strings.out | 9 ++++
src/test/regress/sql/strings.sql | 3 ++
3 files changed, 82 insertions(+), 27 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2025-09-14 01:02:14 pgsql: nbtree: Always set skipScan flag on rescan.
Previous Message Nathan Bossart 2025-09-13 19:59:06 pgsql: Add commit 17a5ca58eb to .git-blame-ignore-revs.