Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/locale/locale_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
42 changes: 42 additions & 0 deletions ext/intl/tests/locale_lookup_empty_language_tags.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Locale::lookup() honors the default locale for an empty language tag list
--EXTENSIONS--
intl
--FILE--
<?php
foreach (['locale_lookup', [Locale::class, 'lookup']] as $lookup) {
foreach ([false, true] as $canonicalize) {
var_dump($lookup([], 'fr_FR', $canonicalize, 'en-US'));
var_dump($lookup([], '', $canonicalize, 'en-US'));
var_dump($lookup([], 'fr_FR', $canonicalize, ''));
var_dump($lookup([], 'fr_FR', $canonicalize, null));
var_dump($lookup([], 'fr_FR', $canonicalize));
var_dump(intl_get_error_code());
}
}
?>
--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)
Loading