Skip to content

Intl locale compose isref #18035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 @@ -9,6 +9,10 @@ PHP NEWS
. Fixed bug GH-17984 (calls with arguments as array with references).
(David Carlier)

- Intl:
. Fix locale_compose and locale_lookup to work with their array argument
with values as references. (David Carlier)

- Embed:
. Fixed bug GH-8533 (Unable to link dynamic libphp on Mac). (Kévin Dunglas)

Expand Down
8 changes: 5 additions & 3 deletions ext/intl/locale/locale_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ static int append_key_value(smart_str* loc_name, HashTable* hash_arr, char* key_
{
zval *ele_value;

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

/* Variant/ Extlang/Private etc. */
if ((ele_value = zend_hash_str_find( hash_arr , key_name , strlen(key_name))) != NULL) {
if ((ele_value = zend_hash_str_find_deref( hash_arr , key_name , strlen(key_name))) != NULL) {
if( Z_TYPE_P(ele_value) == IS_STRING ){
add_prefix( loc_name , key_name);

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

ZEND_HASH_FOREACH_VAL(arr, data) {
ZVAL_DEREF(data);
if(Z_TYPE_P(data) != IS_STRING) {
return FAILURE;
}
Expand Down Expand Up @@ -900,7 +901,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr,
isFirstSubtag = 0;
for( i=0 ; i< max_value; i++ ){
snprintf( cur_key_name , 30, "%s%d", key_name , i);
if ((ele_value = zend_hash_str_find( hash_arr , cur_key_name , strlen(cur_key_name))) != NULL) {
if ((ele_value = zend_hash_str_find_deref( hash_arr , cur_key_name , strlen(cur_key_name))) != NULL) {
if( Z_TYPE_P(ele_value)!= IS_STRING ){
/* variant is not a string */
return FAILURE;
Expand Down Expand Up @@ -1437,6 +1438,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,

char **cur_arr = ecalloc(zend_hash_num_elements(hash_arr)*2, sizeof(char *));
ZEND_HASH_FOREACH_VAL(hash_arr, ele_value) {
ZVAL_DEREF(ele_value);
/* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */
if(Z_TYPE_P(ele_value)!= IS_STRING) {
/* element value is not a string */
Expand Down
29 changes: 29 additions & 0 deletions ext/intl/tests/locale_compose_lookup_references.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
locale_compose()/locale_lookup() with values as references.
--EXTENSIONS--
intl
--FILE--
<?php

$en = 'en';
$data = [Locale::LANG_TAG => 'en', Locale::REGION_TAG => &$en];

var_dump(locale_compose($data));

$data = [
'language' => 'de',
'script' => 'Hans',
'region' => 'DE',
'variant2' => 'fr',
'variant1' => &$en,
'private1' => 'private1',
'private2' => 'private2',
];
var_dump(locale_compose($data));
$data = ['de', &$en];
var_dump(locale_lookup($data, "en", false, "en"));
?>
--EXPECT--
string(5) "en_en"
string(36) "de_Hans_DE_en_fr_x_private1_private2"
string(2) "en"
Loading