| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | 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-09-23 19:40:09 |
| Message-ID: | 179019240902.108284.2431649561108446384@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
This reproduces on master, and zero is only one of the positions that
differ. citext's split_part() splits with a case-insensitive regular
expression and subscripts the resulting array, so it was left behind
when ec0294fb2c8 (v14) taught the core split_part() negative positions.
On master:
- split_part('a,b,c'::citext, ',', -1): NULL, core returns 'c'
- split_part('a,b,c'::citext, ',', 4): NULL, core returns ''
- split_part('a,b,c'::citext, ',', 0): NULL, core raises an error
- split_part('abc'::citext, '', 1): 'a', core returns 'abc'
The last one is the empty delimiter: the regular expression splits
between every character, while the core function treats the whole
string as the only field.
The attached patch keeps the case-insensitive split and applies the
core rules to the result: a negative position counts from the end, a
position past the last field gives an empty string. A zero position
and an empty delimiter, which have no case to ignore, are passed to
the core function, so the error message is the same. Since the
function is part of the extension script, this needs citext 1.9.
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.
Regards,
Manu
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Make-citext-s-split_part-handle-field-positions-like.patch | text/x-patch | 7.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manu | 2026-09-23 19:50:31 | Re: BUG #19641: Unexpected results on an SP-GiST indexed column with a non-deterministic collation |
| Previous Message | Ayush Tiwari | 2026-09-23 19:39:12 | Re: BUG #19687: ALTER SEQUENCE provokes error XX001 could not read blocks |