From 6a447e7437b988062fda6529cc84c6595de09b54 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 15 Dec 2023 06:03:19 +0000 Subject: [PATCH] GH-12943 ext/intl accept C as acceptable locale argument. Close GH-12955 --- NEWS | 4 ++++ ext/intl/dateformat/dateformat_create.cpp | 2 +- ext/intl/tests/gh12943.phpt | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/gh12943.phpt diff --git a/NEWS b/NEWS index c68a4d19740..9960d2eafca 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,10 @@ PHP NEWS (Jakub Zelenka) . Fixed bug GH-12905 (FFI::new interacts badly with observers). (nielsdos) +- Intl: + . Fixed GH-12943 (IntlDateFormatter::__construct accepts 'C' as valid locale). + (David Carlier) + - Hash: . Fixed bug GH-12936 (hash() function hangs endlessly if using sha512 on strings >= 4GiB). (nielsdos) diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 5c96f41fadf..399740dbca2 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -112,7 +112,7 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin } locale = Locale::createFromName(locale_str); /* get*Name accessors being set does not preclude being bogus */ - if (locale.isBogus() || strlen(locale.getISO3Language()) == 0) { + if (locale.isBogus() || ((locale_len == 1 && locale_str[0] != 'C') && strlen(locale.getISO3Language()) == 0)) { goto error; } diff --git a/ext/intl/tests/gh12943.phpt b/ext/intl/tests/gh12943.phpt new file mode 100644 index 00000000000..1a8856640ac --- /dev/null +++ b/ext/intl/tests/gh12943.phpt @@ -0,0 +1,15 @@ +--TEST-- +GitHub #12943 IntlDateFormatter::locale accepting "C". +--EXTENSIONS-- +intl +--FILE-- +getLocale(ULOC_VALID_LOCALE)); +--EXPECTF-- +string(%d) "%s"