Re: SIMILAR TO expressions translate wildcards where they shouldn't
Laurenz Albe <laurenz.albe@cybertec.at>
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-05-23T09:42:10Z
Lists: pgsql-bugs
Attachments
- v2-0001-Fix-SIMILAR-TO-regex-translation-for-character-cl.patch (text/x-patch) patch v2-0001
On Fri, 2025-05-23 at 12:22 +0900, Michael Paquier wrote:
> Anyway, I don't think that the tests in the patch are complete. For
> example, '[[^](]' is transformed into '^(?:[[^](])$' in the SIMILAR TO
> conversion with the patch, and before the patch we get
> '^(?:[[^](?:])$'. Note the translation of the last parenthesis '(' to
> "(?:" when inside the character class, but your patch does not
> document that. AFAIU, we should not convert the parenthesis '(' while
> in a multi-level character class as the patch does, but we have no
> tests for it and the patch does not document this part, either.
>
> Could it be possible to split the single SIMILAR TO expression into
> multiple smaller pieces for each character that should not be
> converted while inside a character class? This is hard to parse as
> written in your proposal of patch.
I have changed the regression test like you suggest.
I also improved the code by adding more comments.
I renamed "incharclass" to "charclass_depth", which is more descriptive.
Also, I had to work some more on handling carets:
While the closing bracket is a regular character in []] and [^]], it
is not in expressions like [^^].
Yours,
Laurenz Albe
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Adjust regex for test with opening parenthesis in character classes
- 31ee5ec698ed 13.22 landed
- 0c09922c04ea 14.19 landed
- 4dc642e75f1c 15.14 landed
- 52d08620e48c 16.10 landed
- a3c6d92f3cb3 17.6 landed
- 4fbb46f61271 18.0 landed
-
Fix conversion of SIMILAR TO regexes for character classes
- 9481d1614c2a 13.22 landed
- 1fe15d25e65c 14.19 landed
- b3e99115e44c 15.14 landed
- e9e535d61120 16.10 landed
- e3ffc3e91d04 17.6 landed
- d46911e584d4 18.0 landed