1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Fix bug in support for collation attributes on older ICU versions

Unrecognized attribute names are supposed to be ignored.  But the code
would error out on an unrecognized attribute value even if it did not
recognize the attribute name.  So unrecognized attributes wouldn't
really be ignored unless the value happened to be one that matched a
recognized value.  This would break some important cases where the
attribute would be processed by ucol_open() directly.  Fix that and
add a test case.

The restructured code should also avoid compiler warnings about
initializing a UColAttribute value to -1, because the type might be an
unsigned enum.  (reported by Andres Freund)
This commit is contained in:
Peter Eisentraut
2019-03-19 09:37:46 +01:00
parent 53680c116c
commit 1f050c08f9
3 changed files with 23 additions and 4 deletions

View File

@ -1623,8 +1623,8 @@ icu_set_collation_attributes(UCollator *collator, const char *loc)
{
char *name;
char *value;
UColAttribute uattr = -1;
UColAttributeValue uvalue = -1;
UColAttribute uattr;
UColAttributeValue uvalue;
UErrorCode status;
status = U_ZERO_ERROR;
@ -1650,7 +1650,9 @@ icu_set_collation_attributes(UCollator *collator, const char *loc)
uattr = UCOL_NORMALIZATION_MODE;
else if (strcmp(name, "colnumeric") == 0)
uattr = UCOL_NUMERIC_COLLATION;
/* ignore if unknown */
else
/* ignore if unknown */
continue;
if (strcmp(value, "primary") == 0)
uvalue = UCOL_PRIMARY;
@ -1677,7 +1679,7 @@ icu_set_collation_attributes(UCollator *collator, const char *loc)
else
status = U_ILLEGAL_ARGUMENT_ERROR;
if (uattr != -1 && uvalue != -1)
if (status == U_ZERO_ERROR)
ucol_setAttribute(collator, uattr, uvalue, &status);
/*