Skip to content

Commit 71d27d8

Browse files
committed
Merge branch 'PHP-8.5'
2 parents 943720b + 469b7b9 commit 71d27d8

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ PHP NEWS
7777
- Intl:
7878
. Fixed malformed ResourceBundle::get() error message when fallback is
7979
disabled. (Weilin Du)
80+
. Fix incorrect argument positions for invalid start/end arguments in
81+
transliterator_transliterate(). (Weilin Du)
8082
. Fixed IntlTimeZone::getDisplayName() to synchronize object error state
8183
for invalid display types. (Weilin Du)
8284
. Added IntlNumberRangeFormatter class to format an interval of two numbers

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.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,16 @@ U_CFUNC PHP_FUNCTION( transliterator_transliterate )
276276
zend_long start = 0,
277277
limit = -1;
278278
int success = 0;
279+
bool is_method;
279280
zval tmp_object;
280281
TRANSLITERATOR_METHOD_INIT_VARS;
281282

282283
object = getThis();
284+
is_method = object != NULL;
283285

284286
ZVAL_UNDEF(&tmp_object);
285287

286-
if (object == nullptr) {
288+
if (!is_method) {
287289
/* in non-OOP version, accept both a transliterator and a string */
288290
zend_string *arg1_str;
289291
zend_object *arg1_obj;
@@ -320,17 +322,17 @@ U_CFUNC PHP_FUNCTION( transliterator_transliterate )
320322
}
321323

322324
if (limit < -1) {
323-
zend_argument_value_error(object ? 3 : 4, "must be greater than or equal to -1");
325+
zend_argument_value_error(is_method ? 3 : 4, "must be greater than or equal to -1");
324326
goto cleanup_object;
325327
}
326328

327329
if (start < 0) {
328-
zend_argument_value_error(object ? 2 : 3, "must be greater than or equal to 0");
330+
zend_argument_value_error(is_method ? 2 : 3, "must be greater than or equal to 0");
329331
goto cleanup_object;
330332
}
331333

332334
if (limit != -1 && start > limit) {
333-
zend_argument_value_error(object ? 2 : 3, "must be less than or equal to argument #%d ($end)", object ? 3 : 4);
335+
zend_argument_value_error(is_method ? 2 : 3, "must be less than or equal to argument #%d ($end)", is_method ? 3 : 4);
334336
goto cleanup_object;
335337
}
336338

0 commit comments

Comments
 (0)