ext/intl: Fix Uconverter::transcode with substitutes as references.

close GH-18059
This commit is contained in:
David Carlier 2025-03-14 07:36:48 +00:00
parent f34859cb90
commit 005c7b5797
No known key found for this signature in database
GPG key ID: 8486F847B4B94EF1
3 changed files with 25 additions and 2 deletions

1
NEWS
View file

@ -20,6 +20,7 @@ PHP NEWS
with values as references. (David Carlier) with values as references. (David Carlier)
. Fix dateformat_format when the time is an array of references. . Fix dateformat_format when the time is an array of references.
(David Carlier) (David Carlier)
. Fix UConverter::transcode with substitutes as references. (David Carlier)
- Embed: - Embed:
. Fixed bug GH-8533 (Unable to link dynamic libphp on Mac). (Kévin Dunglas) . Fixed bug GH-8533 (Unable to link dynamic libphp on Mac). (Kévin Dunglas)

View file

@ -749,13 +749,13 @@ PHP_METHOD(UConverter, transcode) {
zval *tmpzval; zval *tmpzval;
if (U_SUCCESS(error) && if (U_SUCCESS(error) &&
(tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst") - 1)) != NULL && (tmpzval = zend_hash_str_find_deref(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst") - 1)) != NULL &&
Z_TYPE_P(tmpzval) == IS_STRING) { Z_TYPE_P(tmpzval) == IS_STRING) {
error = U_ZERO_ERROR; error = U_ZERO_ERROR;
ucnv_setSubstChars(src_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error); ucnv_setSubstChars(src_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error);
} }
if (U_SUCCESS(error) && if (U_SUCCESS(error) &&
(tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst") - 1)) != NULL && (tmpzval = zend_hash_str_find_deref(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst") - 1)) != NULL &&
Z_TYPE_P(tmpzval) == IS_STRING) { Z_TYPE_P(tmpzval) == IS_STRING) {
error = U_ZERO_ERROR; error = U_ZERO_ERROR;
ucnv_setSubstChars(dest_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error); ucnv_setSubstChars(dest_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error);

View file

@ -0,0 +1,22 @@
--TEST--
UConverter::transcode issue with substitutes values as references
--EXTENSIONS--
intl
--FILE--
<?php
$subst = '??';
$opts = array('from_subst' => '?', 'to_subst' => &$subst);
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
$opts = array('from_subst' => &$subst, 'to_subst' => '?');
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
// should yield the same results
$opts = array('from_subst' => '?', 'to_subst' => '??');
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
$opts = array('from_subst' => '??', 'to_subst' => '?');
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
?>
--EXPECT--
bool(false)
string(23) "This is an ascii string"
bool(false)
string(23) "This is an ascii string"