Skip to content

Commit 455f948

Browse files
committed
Revert "ICU: do not convert locale 'C' to 'en-US-u-va-posix'."
This reverts commit f7faa99. Discussion: https://postgr.es/m/483826.1683582475@sss.pgh.pa.us
1 parent 5698f07 commit 455f948

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,10 +2782,26 @@ icu_language_tag(const char *loc_str, int elevel)
27822782
{
27832783
#ifdef USE_ICU
27842784
UErrorCode status;
2785+
char lang[ULOC_LANG_CAPACITY];
27852786
char *langtag;
27862787
size_t buflen = 32; /* arbitrary starting buffer size */
27872788
const bool strict = true;
27882789

2790+
status = U_ZERO_ERROR;
2791+
uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
2792+
if (U_FAILURE(status))
2793+
{
2794+
if (elevel > 0)
2795+
ereport(elevel,
2796+
(errmsg("could not get language from locale \"%s\": %s",
2797+
loc_str, u_errorName(status))));
2798+
return NULL;
2799+
}
2800+
2801+
/* C/POSIX locales aren't handled by uloc_getLanguageTag() */
2802+
if (strcmp(lang, "c") == 0 || strcmp(lang, "posix") == 0)
2803+
return pstrdup("en-US-u-va-posix");
2804+
27892805
/*
27902806
* A BCP47 language tag doesn't have a clearly-defined upper limit
27912807
* (cf. RFC5646 section 4.4). Additionally, in older ICU versions,
@@ -2873,7 +2889,8 @@ icu_validate_locale(const char *loc_str)
28732889

28742890
/* check for special language name */
28752891
if (strcmp(lang, "") == 0 ||
2876-
strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
2892+
strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0 ||
2893+
strcmp(lang, "c") == 0 || strcmp(lang, "posix") == 0)
28772894
found = true;
28782895

28792896
/* search for matching language within ICU */

src/bin/initdb/initdb.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2238,10 +2238,24 @@ icu_language_tag(const char *loc_str)
22382238
{
22392239
#ifdef USE_ICU
22402240
UErrorCode status;
2241+
char lang[ULOC_LANG_CAPACITY];
22412242
char *langtag;
22422243
size_t buflen = 32; /* arbitrary starting buffer size */
22432244
const bool strict = true;
22442245

2246+
status = U_ZERO_ERROR;
2247+
uloc_getLanguage(loc_str, lang, ULOC_LANG_CAPACITY, &status);
2248+
if (U_FAILURE(status))
2249+
{
2250+
pg_fatal("could not get language from locale \"%s\": %s",
2251+
loc_str, u_errorName(status));
2252+
return NULL;
2253+
}
2254+
2255+
/* C/POSIX locales aren't handled by uloc_getLanguageTag() */
2256+
if (strcmp(lang, "c") == 0 || strcmp(lang, "posix") == 0)
2257+
return pstrdup("en-US-u-va-posix");
2258+
22452259
/*
22462260
* A BCP47 language tag doesn't have a clearly-defined upper limit
22472261
* (cf. RFC5646 section 4.4). Additionally, in older ICU versions,
@@ -2313,7 +2327,8 @@ icu_validate_locale(const char *loc_str)
23132327

23142328
/* check for special language name */
23152329
if (strcmp(lang, "") == 0 ||
2316-
strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0)
2330+
strcmp(lang, "root") == 0 || strcmp(lang, "und") == 0 ||
2331+
strcmp(lang, "c") == 0 || strcmp(lang, "posix") == 0)
23172332
found = true;
23182333

23192334
/* search for matching language within ICU */

src/test/regress/expected/collate.icu.utf8.out

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,6 @@ CREATE ROLE regress_test_role;
10201020
CREATE SCHEMA test_schema;
10211021
-- We need to do this this way to cope with varying names for encodings:
10221022
SET client_min_messages TO WARNING;
1023-
SET icu_validation_level = disabled;
10241023
do $$
10251024
BEGIN
10261025
EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' ||
@@ -1035,24 +1034,17 @@ BEGIN
10351034
quote_literal(current_setting('lc_collate')) || ');';
10361035
END
10371036
$$;
1038-
RESET icu_validation_level;
10391037
RESET client_min_messages;
10401038
CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8'); -- fail, needs "locale"
10411039
ERROR: parameter "locale" must be specified
10421040
CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere'); -- fails
10431041
ERROR: ICU locale "nonsense-nowhere" has unknown language "nonsense"
10441042
HINT: To disable ICU locale validation, set parameter icu_validation_level to DISABLED.
1045-
CREATE COLLATION testx (provider = icu, locale = 'C'); -- fails
1046-
ERROR: could not convert locale name "C" to language tag: U_ILLEGAL_ARGUMENT_ERROR
10471043
CREATE COLLATION testx (provider = icu, locale = '@colStrength=primary;nonsense=yes'); -- fails
10481044
ERROR: could not convert locale name "@colStrength=primary;nonsense=yes" to language tag: U_ILLEGAL_ARGUMENT_ERROR
10491045
SET icu_validation_level = WARNING;
10501046
CREATE COLLATION testx (provider = icu, locale = '@colStrength=primary;nonsense=yes'); DROP COLLATION testx;
10511047
WARNING: could not convert locale name "@colStrength=primary;nonsense=yes" to language tag: U_ILLEGAL_ARGUMENT_ERROR
1052-
CREATE COLLATION testx (provider = icu, locale = 'C'); DROP COLLATION testx;
1053-
WARNING: could not convert locale name "C" to language tag: U_ILLEGAL_ARGUMENT_ERROR
1054-
WARNING: ICU locale "C" has unknown language "c"
1055-
HINT: To disable ICU locale validation, set parameter icu_validation_level to DISABLED.
10561048
CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere'); DROP COLLATION testx;
10571049
WARNING: ICU locale "nonsense-nowhere" has unknown language "nonsense"
10581050
HINT: To disable ICU locale validation, set parameter icu_validation_level to DISABLED.

src/test/regress/sql/collate.icu.utf8.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ CREATE SCHEMA test_schema;
358358

359359
-- We need to do this this way to cope with varying names for encodings:
360360
SET client_min_messages TO WARNING;
361-
SET icu_validation_level = disabled;
362361

363362
do $$
364363
BEGIN
@@ -374,16 +373,13 @@ BEGIN
374373
END
375374
$$;
376375

377-
RESET icu_validation_level;
378376
RESET client_min_messages;
379377

380378
CREATE COLLATION test3 (provider = icu, lc_collate = 'en_US.utf8'); -- fail, needs "locale"
381379
CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere'); -- fails
382-
CREATE COLLATION testx (provider = icu, locale = 'C'); -- fails
383380
CREATE COLLATION testx (provider = icu, locale = '@colStrength=primary;nonsense=yes'); -- fails
384381
SET icu_validation_level = WARNING;
385382
CREATE COLLATION testx (provider = icu, locale = '@colStrength=primary;nonsense=yes'); DROP COLLATION testx;
386-
CREATE COLLATION testx (provider = icu, locale = 'C'); DROP COLLATION testx;
387383
CREATE COLLATION testx (provider = icu, locale = 'nonsense-nowhere'); DROP COLLATION testx;
388384
RESET icu_validation_level;
389385

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy