Re: BUG #19602: Vuln46: citext split_part silently returns NULL for a zero field position instead of raising core sp

From: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: Manu <manuelreyesbravo(at)gmail(dot)com>, 1217816127(at)qq(dot)com
Subject: Re: BUG #19602: Vuln46: citext split_part silently returns NULL for a zero field position instead of raising core sp
Date: 2026-11-10 13:42:26
Message-ID: CAJ7c6TNFpcjYKwdq_oi=wM8LLaYX8NzMwr8NBhZuacxByGKntg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Manu,

> Tested on master:
>
> - the citext regression tests pass, with new cases for all of the above;
> - ALTER EXTENSION citext UPDATE TO '1.9' changes the -1 case from NULL
> to 'c' in an existing database;
> - on 20000 random lower-case strings, delimiters of up to three
> characters (some of them regex metacharacters) and positions from -6
> to 6, the result matches the core split_part() in every case.

I think v1 can be simplified like this:

```
RETURN pg_catalog.split_part(
pg_catalog.regexp_replace(
$1::pg_catalog.text,
pg_catalog.regexp_replace($2::pg_catalog.text,
'([^a-zA-Z_0-9])', E'\\\\\\1', 'g'),
pg_catalog.replace($2::pg_catalog.text, E'\\', E'\\\\'),
'gi'),
$2::pg_catalog.text,
$3);
```

Without WHEN .. ELSE and COALESCE it should be faster too.

Thoughts?

--
Best regards,
Aleksander Alekseev

Attachment Content-Type Size
v1-changes.txt text/plain 2.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Corey Huinker 2026-11-10 17:01:13 Re: BUG #19857: Stats restore rejects empty arrays, losing range and array stats
Previous Message Andrey Rachitskiy 2026-11-10 11:51:46 Re: BUG #19590: to_date/to_timestamp "Y,YYY" accepts out-of-range values