From: Laurenz Albe <laurenz.albe@cybertec.at>
To: adam.warland@infor.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Date: Tue, 02 Dec 2025 17:31:54 +0100
Message-ID: <a0d41b12dc6067b6e679bfd18f8a050704bc9902.camel@cybertec.at> (raw)
In-Reply-To: <60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at>
References: <19341-1d9a22915edfec58@postgresql.org>
<60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at>
On Tue, 2025-12-02 at 17:24 +0100, Laurenz Albe wrote:
> I can reproduce the problem, and the attached patch fixes it for me.
Erm, and here is the patch.
Laurenz Albe
Attachments:
[text/x-patch] v1-0001-Fix-greedy-substring-search-for-non-deterministic.patch (1.3K, ../a0d41b12dc6067b6e679bfd18f8a050704bc9902.camel@cybertec.at/2-v1-0001-Fix-greedy-substring-search-for-non-deterministic.patch)
download | inline diff:
From 057e4348a2c44816e19e9c5c4711626263a877c4 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
Date: Tue, 2 Dec 2025 17:20:27 +0100
Subject: [PATCH v1] Fix greedy substring search for non-deterministic
collations
Due to an off-by-one error, the code failed to find matches at the
end of the haystack.
Author: Laurenz Albe <laurenz.albe@cybertec.at>
Reported-By: Adam Warland <adam.warland@infor.com>
Discussion: https://postgr.es/m/19341-1d9a22915edfec58%40postgresql.org
---
src/backend/utils/adt/varlena.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.cindex 3894457ab40..7fe109ba73e 100644--- a/src/backend/utils/adt/varlena.c+++ b/src/backend/utils/adt/varlena.c@@ -1149,7 +1149,7 @@ text_position_next_internal(char *start_ptr, TextPositionState *state)
* Else check if any of the possible substrings starting at hptr
* are equal to the needle.
*/
- for (const char *test_end = hptr; test_end < haystack_end; test_end += pg_mblen(test_end))+ for (const char *test_end = hptr; test_end <= haystack_end; test_end += pg_mblen(test_end))
{
if (pg_strncoll(hptr, (test_end - hptr), needle, needle_len, state->locale) == 0)
{
--
2.52.0
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: laurenz.albe@cybertec.at, adam.warland@infor.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
In-Reply-To: <a0d41b12dc6067b6e679bfd18f8a050704bc9902.camel@cybertec.at>
* 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