Skip to content

Commit 469b7b9

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
2 parents fa0e11f + d8e7418 commit 469b7b9

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
overflow-triggered early return). (iliaal)
2525

2626
- Intl:
27+
. Fix incorrect argument positions for invalid start/end arguments in
28+
transliterator_transliterate().
29+
(Weilin Du)
2730
. Fixed IntlTimeZone::getDisplayName() to synchronize object error state
2831
for invalid display types. (Weilin Du)
2932

ext/intl/tests/transliterator_transliterate_error.phpt

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,38 @@ intl.use_exceptions=true
99

1010
$tr = Transliterator::create("latin");
1111

12-
try {
13-
var_dump(transliterator_transliterate($tr, "str", 7));
14-
} catch (Throwable $e) {
15-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
function dump_throwable(callable $callback): void {
13+
try {
14+
$callback();
15+
} catch (Throwable $e) {
16+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
17+
}
1618
}
1719

18-
try {
20+
//Arguments
21+
dump_throwable(function() use ($tr) {
22+
var_dump(transliterator_transliterate($tr, "str", 7));
23+
});
24+
25+
dump_throwable(function() use ($tr) {
1926
transliterator_transliterate($tr, "str", 7, 6);
20-
} catch (Throwable $e) {
21-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
22-
}
27+
});
28+
29+
dump_throwable(function() use ($tr) {
30+
transliterator_transliterate($tr, "str", 0, -2);
31+
});
32+
33+
dump_throwable(function() use ($tr) {
34+
transliterator_transliterate($tr, "str", -1);
35+
});
36+
37+
dump_throwable(function() {
38+
transliterator_transliterate("latin", "str", -1);
39+
});
40+
41+
dump_throwable(function() use ($tr) {
42+
$tr->transliterate("str", 7, 6);
43+
});
2344

2445
//bad UTF-8
2546
try {
@@ -31,5 +52,9 @@ try {
3152
?>
3253
--EXPECT--
3354
IntlException: transliterator_transliterate(): Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3)
34-
ValueError: transliterator_transliterate(): Argument #2 ($string) must be less than or equal to argument #3 ($end)
55+
ValueError: transliterator_transliterate(): Argument #3 ($start) must be less than or equal to argument #4 ($end)
56+
ValueError: transliterator_transliterate(): Argument #4 ($end) must be greater than or equal to -1
57+
ValueError: transliterator_transliterate(): Argument #3 ($start) must be greater than or equal to 0
58+
ValueError: transliterator_transliterate(): Argument #3 ($start) must be greater than or equal to 0
59+
ValueError: Transliterator::transliterate(): Argument #2 ($start) must be less than or equal to argument #3 ($end)
3560
IntlException: transliterator_transliterate(): String conversion of string to UTF-16 failed

ext/intl/transliterator/transliterator_methods.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,16 @@ PHP_FUNCTION( transliterator_transliterate )
269269
zend_long start = 0,
270270
limit = -1;
271271
int success = 0;
272+
bool is_method;
272273
zval tmp_object;
273274
TRANSLITERATOR_METHOD_INIT_VARS;
274275

275276
object = getThis();
277+
is_method = object != NULL;
276278

277279
ZVAL_UNDEF(&tmp_object);
278280

279-
if (object == NULL) {
281+
if (!is_method) {
280282
/* in non-OOP version, accept both a transliterator and a string */
281283
zend_string *arg1_str;
282284
zend_object *arg1_obj;
@@ -313,17 +315,17 @@ PHP_FUNCTION( transliterator_transliterate )
313315
}
314316

315317
if (limit < -1) {
316-
zend_argument_value_error(object ? 3 : 4, "must be greater than or equal to -1");
318+
zend_argument_value_error(is_method ? 3 : 4, "must be greater than or equal to -1");
317319
goto cleanup_object;
318320
}
319321

320322
if (start < 0) {
321-
zend_argument_value_error(object ? 2 : 3, "must be greater than or equal to 0");
323+
zend_argument_value_error(is_method ? 2 : 3, "must be greater than or equal to 0");
322324
goto cleanup_object;
323325
}
324326

325327
if (limit != -1 && start > limit) {
326-
zend_argument_value_error(object ? 2 : 3, "must be less than or equal to argument #%d ($end)", object ? 3 : 4);
328+
zend_argument_value_error(is_method ? 2 : 3, "must be less than or equal to argument #%d ($end)", is_method ? 3 : 4);
327329
goto cleanup_object;
328330
}
329331

0 commit comments

Comments
 (0)