Skip to content

Commit 005c7b5

Browse files
committed
ext/intl: Fix Uconverter::transcode with substitutes as references.
close GH-18059
1 parent f34859c commit 005c7b5

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
with values as references. (David Carlier)
2121
. Fix dateformat_format when the time is an array of references.
2222
(David Carlier)
23+
. Fix UConverter::transcode with substitutes as references. (David Carlier)
2324

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

ext/intl/converter/converter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,13 @@ PHP_METHOD(UConverter, transcode) {
749749
zval *tmpzval;
750750

751751
if (U_SUCCESS(error) &&
752-
(tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst") - 1)) != NULL &&
752+
(tmpzval = zend_hash_str_find_deref(Z_ARRVAL_P(options), "from_subst", sizeof("from_subst") - 1)) != NULL &&
753753
Z_TYPE_P(tmpzval) == IS_STRING) {
754754
error = U_ZERO_ERROR;
755755
ucnv_setSubstChars(src_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error);
756756
}
757757
if (U_SUCCESS(error) &&
758-
(tmpzval = zend_hash_str_find(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst") - 1)) != NULL &&
758+
(tmpzval = zend_hash_str_find_deref(Z_ARRVAL_P(options), "to_subst", sizeof("to_subst") - 1)) != NULL &&
759759
Z_TYPE_P(tmpzval) == IS_STRING) {
760760
error = U_ZERO_ERROR;
761761
ucnv_setSubstChars(dest_cnv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval) & 0x7F, &error);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
UConverter::transcode issue with substitutes values as references
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
$subst = '??';
8+
$opts = array('from_subst' => '?', 'to_subst' => &$subst);
9+
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
10+
$opts = array('from_subst' => &$subst, 'to_subst' => '?');
11+
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
12+
// should yield the same results
13+
$opts = array('from_subst' => '?', 'to_subst' => '??');
14+
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
15+
$opts = array('from_subst' => '??', 'to_subst' => '?');
16+
var_dump(UConverter::transcode("This is an ascii string", 'ascii', 'utf-8', $opts));
17+
?>
18+
--EXPECT--
19+
bool(false)
20+
string(23) "This is an ascii string"
21+
bool(false)
22+
string(23) "This is an ascii string"

0 commit comments

Comments
 (0)