From 235297daeda99773f68ee59e2efff048e98c1dc5 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Fri, 27 Aug 2021 14:49:11 +0900 Subject: [PATCH] Fix #81383: Locale::lookup / locale_lookup incorrectly returns null instead of default INTL_MAX_LOCALE_LEN limits the length of accepted locale. Anything longer than that will result in a failure and the value returned will either be `null` or `false`. So documentation must reflect that in the return types. Co-authored-by: Christoph M. Becker Closes GH-883. --- language-snippets.ent | 2 ++ reference/intl/locale/accept-from-http.xml | 8 ++++++-- reference/intl/locale/canonicalize.xml | 9 ++++++--- reference/intl/locale/filter-matches.xml | 15 ++++++++------- reference/intl/locale/get-all-variants.xml | 7 ++++--- reference/intl/locale/get-keywords.xml | 9 +++++---- reference/intl/locale/get-primary-language.xml | 7 ++++--- reference/intl/locale/get-region.xml | 5 +++-- reference/intl/locale/lookup.xml | 11 ++++++----- reference/intl/locale/parse-locale.xml | 4 ++-- 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/language-snippets.ent b/language-snippets.ent index e59c05dd5eae..de717575cf24 100644 --- a/language-snippets.ent +++ b/language-snippets.ent @@ -1010,6 +1010,8 @@ Passing untrusted data to this parameter is insecure, unles +Returns &null; when the length of locale exceeds INTL_MAX_LOCALE_LEN.'> + The Unicode property to lookup (see the IntlChar::PROPERTY_* constants).'> diff --git a/reference/intl/locale/accept-from-http.xml b/reference/intl/locale/accept-from-http.xml index b84ba84c0499..4553ec4c86a4 100644 --- a/reference/intl/locale/accept-from-http.xml +++ b/reference/intl/locale/accept-from-http.xml @@ -15,7 +15,7 @@ public static - string + stringfalse Locale::acceptFromHttp stringheader @@ -23,7 +23,7 @@ &style.procedural; - string + stringfalse locale_accept_from_http stringheader @@ -55,6 +55,10 @@ The corresponding locale identifier. + + Returns &false; when the length of header exceeds + INTL_MAX_LOCALE_LEN. + diff --git a/reference/intl/locale/canonicalize.xml b/reference/intl/locale/canonicalize.xml index 501d6a46babe..af7d971e24a0 100644 --- a/reference/intl/locale/canonicalize.xml +++ b/reference/intl/locale/canonicalize.xml @@ -11,7 +11,9 @@ &reftitle.description; - public static stringLocale::canonicalize + public static + stringnull + Locale::canonicalize stringlocale @@ -29,7 +31,7 @@ locale - + @@ -39,8 +41,9 @@ &reftitle.returnvalues; - + Canonicalized locale string. + &intl.locale-len.return; diff --git a/reference/intl/locale/filter-matches.xml b/reference/intl/locale/filter-matches.xml index ab72498c4ee7..30feb51cc3d9 100644 --- a/reference/intl/locale/filter-matches.xml +++ b/reference/intl/locale/filter-matches.xml @@ -15,7 +15,7 @@ public static - bool + boolnull Locale::filterMatches stringlangtag stringlocale @@ -25,7 +25,7 @@ &style.procedural; - bool + boolnull locale_filter_matches stringlangtag stringlocale @@ -62,7 +62,7 @@ If true, the arguments will be converted to canonical form before - matching. + matching. @@ -76,6 +76,7 @@ &true; if $locale matches $langtag &false; otherwise. + &intl.locale-len.return; @@ -85,9 +86,9 @@ ]]> @@ -97,9 +98,9 @@ echo (locale_filter_matches('de-DE_1996','de-DE', false)) ? "Matches" : "Does no ]]> diff --git a/reference/intl/locale/get-all-variants.xml b/reference/intl/locale/get-all-variants.xml index cd05ef1734c7..b841075af794 100644 --- a/reference/intl/locale/get-all-variants.xml +++ b/reference/intl/locale/get-all-variants.xml @@ -15,7 +15,7 @@ public static - array + arraynull Locale::getAllVariants stringlocale @@ -23,7 +23,7 @@ &style.procedural; - array + arraynull locale_get_all_variants stringlocale @@ -52,9 +52,10 @@ &reftitle.returnvalues; - The array containing the list of all variants subtag for the locale + The array containing the list of all variants subtag for the locale or &null; if not present + &intl.locale-len.return; diff --git a/reference/intl/locale/get-keywords.xml b/reference/intl/locale/get-keywords.xml index c546cdea9698..5832058b05fd 100644 --- a/reference/intl/locale/get-keywords.xml +++ b/reference/intl/locale/get-keywords.xml @@ -15,7 +15,7 @@ public static - array + arraynull Locale::getKeywords stringlocale @@ -23,7 +23,7 @@ &style.procedural; - array + arraynull locale_get_keywords stringlocale @@ -54,6 +54,7 @@ Associative array containing the keyword-value pairs for this locale + &intl.locale-len.return; @@ -66,7 +67,7 @@ $keywords_arr = locale_get_keywords('de_DE@currency=EUR;collation=PHONEBOOK'); if ($keywords_arr) { foreach ($keywords_arr as $key => $value) { - echo "$key = $value\n"; + echo "$key = $value\n"; } } ?> @@ -81,7 +82,7 @@ if ($keywords_arr) { $keywords_arr = Locale::getKeywords('de_DE@currency=EUR;collation=PHONEBOOK'); if ($keywords_arr) { foreach ($keywords_arr as $key => $value) { - echo "$key = $value\n"; + echo "$key = $value\n"; } } ?> diff --git a/reference/intl/locale/get-primary-language.xml b/reference/intl/locale/get-primary-language.xml index f25d63a86a9f..97d49898119b 100644 --- a/reference/intl/locale/get-primary-language.xml +++ b/reference/intl/locale/get-primary-language.xml @@ -15,7 +15,7 @@ public static - string + stringnull Locale::getPrimaryLanguage stringlocale @@ -23,7 +23,7 @@ &style.procedural; - string + stringnull locale_get_primary_language stringlocale @@ -52,8 +52,9 @@ &reftitle.returnvalues; - The language code associated with the language or &null; in case of error. + The language code associated with the language. + &intl.locale-len.return; diff --git a/reference/intl/locale/get-region.xml b/reference/intl/locale/get-region.xml index 1ecf758dae3c..eba93917d910 100644 --- a/reference/intl/locale/get-region.xml +++ b/reference/intl/locale/get-region.xml @@ -15,7 +15,7 @@ public static - string + stringnull Locale::getRegion stringlocale @@ -23,7 +23,7 @@ &style.procedural; - string + stringnull locale_get_region stringlocale @@ -54,6 +54,7 @@ The region subtag for the locale or &null; if not present + &intl.locale-len.return; diff --git a/reference/intl/locale/lookup.xml b/reference/intl/locale/lookup.xml index fb1d90ddb2dd..9fd6ae7b8000 100644 --- a/reference/intl/locale/lookup.xml +++ b/reference/intl/locale/lookup.xml @@ -15,7 +15,7 @@ public static - string + stringnull Locale::lookup arraylangtag stringlocale @@ -26,7 +26,7 @@ &style.procedural; - string + stringnull locale_lookup arraylangtag stringlocale @@ -34,9 +34,9 @@ stringdefault - Searches the items in langtag for the best match to + Searches the items in langtag for the best match to the language range specified in locale according to - RFC 4647's lookup algorithm. + RFC 4647's lookup algorithm. @@ -48,7 +48,7 @@ langtag - An array containing a list of language tags to compare to + An array containing a list of language tags to compare to locale. Maximum 100 items allowed. @@ -90,6 +90,7 @@ The closest matching language tag or default value. + &intl.locale-len.return; diff --git a/reference/intl/locale/parse-locale.xml b/reference/intl/locale/parse-locale.xml index d6acbe7fc0c1..a615d07f5a25 100644 --- a/reference/intl/locale/parse-locale.xml +++ b/reference/intl/locale/parse-locale.xml @@ -15,7 +15,7 @@ public static - array + arraynull Locale::parseLocale stringlocale @@ -23,7 +23,7 @@ &style.procedural; - array + arraynull locale_parse stringlocale