pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix conversion of SIMILAR TO regexes for character classes
Date: Wed, 28 May 2025 00:00:03 +0000
Message-ID: <E1uK4DB-000LnD-2u@gemulon.postgresql.org> (raw)
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
Branch
------
REL_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e9e535d611204266a3c2b587afd9ffbe346fc067
Modified Files
--------------
src/backend/utils/adt/regexp.c | 38 +++++++++++++++++----
src/test/regress/expected/strings.out | 62 +++++++++++++++++++++++++++++++++++
src/test/regress/sql/strings.sql | 20 +++++++++++
3 files changed, 114 insertions(+), 6 deletions(-)
view thread (6+ messages) latest in thread
Message-ID: <E1uK4DB-000LnD-2u@gemulon.postgresql.org> Permalink: ../E1uK4DB-000LnD-2u@gemulon.postgresql.org/ Also on: postgresql.org/message-id/E1uK4DB-000LnD-2u@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: michael@paquier.xyz, pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Fix conversion of SIMILAR TO regexes for character classes In-Reply-To: <E1uK4DB-000LnD-2u@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