Re: SIMILAR TO expressions translate wildcards where they shouldn't

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't
Date: 2025-05-23 01:10:04
Message-ID: aC_K7JPXF0AdPZqB@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Kapila 2025-05-23 03:00:35 Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5
Previous Message Michael Paquier 2025-05-22 23:47:40 Re: Standby server with cascade logical replication could not be properly stopped under load