From 4811d4d608602112c852b421cfd1374efb6f7982 Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Sun, 15 Nov 2026 11:25:05 +0800 Subject: [PATCH] ext/intl: Fix Locale::lookup() ignoring the default locale for an empty language tag list --- NEWS | 4 ++ ext/intl/locale/locale_methods.c | 3 ++ .../locale_lookup_empty_language_tags.phpt | 42 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 ext/intl/tests/locale_lookup_empty_language_tags.phpt diff --git a/NEWS b/NEWS index 64c61f8f121b..0b3edfc34628 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,10 @@ PHP NEWS . Fixed stack overflow in filter_var() and filter_var_array() with deeply nested arrays. (Eyüp Can Akman) +- Intl: + . Fixed Locale::lookup() ignoring the default locale when the language tag + list is empty. (Weilin Du) + - MBString: . Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with deeply nested arrays. (Eyüp Can Akman) diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index 2643f4920878..1b61794d67fb 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -1560,6 +1560,9 @@ PHP_FUNCTION(locale_lookup) INTL_CHECK_LOCALE_LEN(loc_range_len); if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) { + if (fallback_loc_str) { + RETURN_STR_COPY(fallback_loc_str); + } RETURN_EMPTY_STRING(); } diff --git a/ext/intl/tests/locale_lookup_empty_language_tags.phpt b/ext/intl/tests/locale_lookup_empty_language_tags.phpt new file mode 100644 index 000000000000..b0bb2d1e6993 --- /dev/null +++ b/ext/intl/tests/locale_lookup_empty_language_tags.phpt @@ -0,0 +1,42 @@ +--TEST-- +Locale::lookup() honors the default locale for an empty language tag list +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +string(5) "en-US" +string(5) "en-US" +string(0) "" +string(0) "" +string(0) "" +int(0) +string(5) "en-US" +string(5) "en-US" +string(0) "" +string(0) "" +string(0) "" +int(0) +string(5) "en-US" +string(5) "en-US" +string(0) "" +string(0) "" +string(0) "" +int(0) +string(5) "en-US" +string(5) "en-US" +string(0) "" +string(0) "" +string(0) "" +int(0)