Allow setting the collation strength in ICU tailoring rules

There was a bug that if you created an ICU collation with tailoring
rules, any strength specification inside the rules was ignored.  This
was because we called ucol_openRules() with UCOL_DEFAULT_STRENGTH for
the strength argument, which overrides the strength.  This was because
of faulty guidance in the ICU documentation, which has since been
fixed.  The correct invocation is to use UCOL_DEFAULT for the strength
argument.

This fixes bug #18771 and bug #19425.

Author: Daniel Verite <daniel@manitou-mail.org>
Reported-by: Ruben Ruiz <ruben.ruizcuadrado@gmail.com>
Reported-by: dorian.752@live.fr
Reported-by: Todd Lang <Todd.Lang@D2L.com>
Discussion: https://www.postgresql.org/message-id/flat/YT2PPF959236618377A072745A280E278F4BE1DA@YT2PPF959236618.CANPRD01.PROD.OUTLOOK.COM
Discussion: https://www.postgresql.org/message-id/flat/18771-98bb23e455b0f367@postgresql.org
Discussion: https://www.postgresql.org/message-id/flat/19425-58915e19dacd4f40%40postgresql.org
This commit is contained in:
Peter Eisentraut 2026-03-18 08:54:35 +01:00
parent 374a6394c6
commit 905e44152a
3 changed files with 13 additions and 1 deletions

View file

@ -587,7 +587,7 @@ make_icu_collator(const char *iculocstr, const char *icurules)
status = U_ZERO_ERROR;
collator_all_rules = ucol_openRules(all_rules, u_strlen(all_rules),
UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH,
UCOL_DEFAULT, UCOL_DEFAULT,
NULL, &status);
if (U_FAILURE(status))
{

View file

@ -1297,6 +1297,14 @@ DROP TABLE test7;
CREATE COLLATION testcoll_rulesx (provider = icu, locale = '', rules = '!!wrong!!');
NOTICE: using standard form "und" for ICU locale ""
ERROR: could not open collator for locale "und" with rules "!!wrong!!": U_INVALID_FORMAT_ERROR
-- strength specified in the rules
CREATE COLLATION strength_in_rule (provider = icu, locale = 'und', deterministic = false, rules = '[strength 1]');
SELECT 'a' = 'à' COLLATE strength_in_rule; -- true because of the rule
?column?
----------
t
(1 row)
-- nondeterministic collations
CREATE COLLATION ctest_det (provider = icu, locale = '', deterministic = true);
NOTICE: using standard form "und" for ICU locale ""

View file

@ -513,6 +513,10 @@ DROP TABLE test7;
CREATE COLLATION testcoll_rulesx (provider = icu, locale = '', rules = '!!wrong!!');
-- strength specified in the rules
CREATE COLLATION strength_in_rule (provider = icu, locale = 'und', deterministic = false, rules = '[strength 1]');
SELECT 'a' = 'à' COLLATE strength_in_rule; -- true because of the rule
-- nondeterministic collations