pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't
Date: Fri, 23 May 2025 10:10:04 +0900
Message-ID: <aC_K7JPXF0AdPZqB@paquier.xyz> (raw)
In-Reply-To: <16ab039d1af455652bdf4173402ddda145f2c73b.camel@cybertec.at>
References: <16ab039d1af455652bdf4173402ddda145f2c73b.camel@cybertec.at>

On Thu, May 22, 2025 at 11:18:44PM +0200, Laurenz Albe wrote:
> The underscore before the [:alpha:] is left alone, but the one after
> it gets translated to a period.  Now the underscore is a wildcard
> that corresponds to the period in regular expressions, but characters
> in square brackets should lose their special meaning.  The code in
> utils/adt/regexp.c doesn't expect that square brackets can be nested.
> 
> The attached patch fixes the bug.

Oh, good catch.  [_[:alpha:]] and [[:alpha:]_] both that this should
match every string made of a-zA-Z and underscores, but this is failing
to do the job for the latter.

+           if (pchar != '^' && charclass_start)
+               charclass_start = false;

I'm a bit puzzled by this part about '^', though, resetting the fact
that we are in a squared bracket section with '^' treated as an
exception.  Perhaps this deserves a comment?
--
Michael

Attachments:

  [application/pgp-signature] signature.asc (832B, ../aC_K7JPXF0AdPZqB@paquier.xyz/2-signature.asc)
  download

view thread (11+ messages)  latest in thread

Message-ID: <aC_K7JPXF0AdPZqB@paquier.xyz>
Permalink:  ../aC_K7JPXF0AdPZqB@paquier.xyz/
Also on:    postgresql.org/message-id/aC_K7JPXF0AdPZqB@paquier.xyz

 · 

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-bugs@postgresql.org
  Cc: michael@paquier.xyz, laurenz.albe@cybertec.at, pgsql-bugs@lists.postgresql.org
  Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't
  In-Reply-To: <aC_K7JPXF0AdPZqB@paquier.xyz>

* 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