pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Amend recent fix for SIMILAR TO regex conversion.
Date: Sat, 13 Sep 2025 20:56:15 +0000
Message-ID: <E1uxXI7-000Ywb-0R@gemulon.postgresql.org> (raw)

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

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e09adb5b9fc9dec27c7ff9e9592723d7d8098b03

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(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1uxXI7-000Ywb-0R@gemulon.postgresql.org>
Permalink:  ../E1uxXI7-000Ywb-0R@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uxXI7-000Ywb-0R@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Amend recent fix for SIMILAR TO regex conversion.
  In-Reply-To: <E1uxXI7-000Ywb-0R@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox