Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation - Mailing list pgsql-bugs

From Laurenz Albe
Subject Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Date
Msg-id 60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at
Whole thread Raw
In response to BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
List pgsql-bugs
On Tue, 2025-12-02 at 10:03 +0000, PG Bug reporting form wrote:
> PostgreSQL version: 18.1
>
> When using a nondeterministic ICU collation, the replace() function fails to
> replace a substring when that substring appears at the end of the input
> string.
>
> Occurrences of the same substring earlier in the string are replaced
> normally.
>
> Specific collation used:
> create collation test_nondeterministic (
>     provider = icu,
>     locale = 'und-u-ks-level2',
>     deterministic = false
> )
>
> -- Replace final character under nondeterministic collation
> SELECT replace(
>     'testx' COLLATE "test_nondeterministic",
>     'x'     COLLATE "test_nondeterministic",
>     'y') AS res1;

I can reproduce the problem, and the attached patch fixes it for me.

I am not certain if it is safe to apply pg_mblen() to "haystack_end", though.

Yours,
Laurenz Albe



pgsql-bugs by date:

Previous
From: Oleg Ivanov
Date:
Subject: Re: BUG #19340: Wrong result from CORR() function
Next
From: Laurenz Albe
Date:
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation