Skip to content

Commit c3fc94c

Browse files
committed
ext/intl: fix locale_compose/locale_lookup to be able to deal with references.
close GH-18035
1 parent 517d7d9 commit c3fc94c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug GH-17984 (calls with arguments as array with references).
1010
(David Carlier)
1111

12+
- Intl:
13+
. Fix locale_compose and locale_lookup to work with their array argument
14+
with values as references. (David Carlier)
15+
1216
- Embed:
1317
. Fixed bug GH-8533 (Unable to link dynamic libphp on Mac). (Kévin Dunglas)
1418

ext/intl/locale/locale_methods.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ static int append_key_value(smart_str* loc_name, HashTable* hash_arr, char* key_
814814
{
815815
zval *ele_value;
816816

817-
if ((ele_value = zend_hash_str_find(hash_arr , key_name, strlen(key_name))) != NULL ) {
817+
if ((ele_value = zend_hash_str_find_deref(hash_arr , key_name, strlen(key_name))) != NULL ) {
818818
if(Z_TYPE_P(ele_value)!= IS_STRING ){
819819
/* element value is not a string */
820820
return FAILURE;
@@ -857,7 +857,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr,
857857
int isFirstSubtag = 0;
858858

859859
/* Variant/ Extlang/Private etc. */
860-
if ((ele_value = zend_hash_str_find( hash_arr , key_name , strlen(key_name))) != NULL) {
860+
if ((ele_value = zend_hash_str_find_deref( hash_arr , key_name , strlen(key_name))) != NULL) {
861861
if( Z_TYPE_P(ele_value) == IS_STRING ){
862862
add_prefix( loc_name , key_name);
863863

@@ -869,6 +869,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr,
869869
zval *data;
870870

871871
ZEND_HASH_FOREACH_VAL(arr, data) {
872+
ZVAL_DEREF(data);
872873
if(Z_TYPE_P(data) != IS_STRING) {
873874
return FAILURE;
874875
}
@@ -900,7 +901,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr,
900901
isFirstSubtag = 0;
901902
for( i=0 ; i< max_value; i++ ){
902903
snprintf( cur_key_name , 30, "%s%d", key_name , i);
903-
if ((ele_value = zend_hash_str_find( hash_arr , cur_key_name , strlen(cur_key_name))) != NULL) {
904+
if ((ele_value = zend_hash_str_find_deref( hash_arr , cur_key_name , strlen(cur_key_name))) != NULL) {
904905
if( Z_TYPE_P(ele_value)!= IS_STRING ){
905906
/* variant is not a string */
906907
return FAILURE;
@@ -1437,6 +1438,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
14371438

14381439
char **cur_arr = ecalloc(zend_hash_num_elements(hash_arr)*2, sizeof(char *));
14391440
ZEND_HASH_FOREACH_VAL(hash_arr, ele_value) {
1441+
ZVAL_DEREF(ele_value);
14401442
/* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */
14411443
if(Z_TYPE_P(ele_value)!= IS_STRING) {
14421444
/* element value is not a string */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
locale_compose()/locale_lookup() with values as references.
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$en = 'en';
9+
$data = [Locale::LANG_TAG => 'en', Locale::REGION_TAG => &$en];
10+
11+
var_dump(locale_compose($data));
12+
13+
$data = [
14+
'language' => 'de',
15+
'script' => 'Hans',
16+
'region' => 'DE',
17+
'variant2' => 'fr',
18+
'variant1' => &$en,
19+
'private1' => 'private1',
20+
'private2' => 'private2',
21+
];
22+
var_dump(locale_compose($data));
23+
$data = ['de', &$en];
24+
var_dump(locale_lookup($data, "en", false, "en"));
25+
?>
26+
--EXPECT--
27+
string(5) "en_en"
28+
string(36) "de_Hans_DE_en_fr_x_private1_private2"
29+
string(2) "en"

0 commit comments

Comments
 (0)