Skip to content

Commit 4342059

Browse files
authored
ext/intl: better errors for IntlTimeZone::createTimeZoneIDEnumeration (#19395)
IntlTimeZone::createTimeZoneIDEnumeration And convert those to ValueErrors directly as they are bugs
1 parent ca5667b commit 4342059

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
--TEST--
2-
IntlTimeZone::createTimeZoneIDEnumeration(): errors
2+
IntlTimeZone::createTimeZoneIDEnumeration() invalid zone type
33
--EXTENSIONS--
44
intl
55
--FILE--
66
<?php
7-
ini_set("intl.error_level", E_WARNING);
87

9-
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
8+
try {
9+
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
13+
1014
?>
11-
--EXPECTF--
12-
Warning: IntlTimeZone::createTimeZoneIDEnumeration(): bad zone type in %s on line %d
13-
bool(false)
15+
--EXPECT--
16+
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be one of IntlTimeZone::TYPE_ANY, IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
IntlTimeZone::createTimeZoneIDEnumeration() offset out of range
3+
--EXTENSIONS--
4+
intl
5+
--SKIPIF--
6+
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, '', PHP_INT_MAX));
12+
} catch (Throwable $e) {
13+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
14+
}
15+
?>
16+
--EXPECT--
17+
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be between -2147483648 and 2147483647

ext/intl/timezone/timezone_methods.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,17 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
229229

230230
if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL
231231
&& zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
232-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "bad zone type");
233-
RETURN_FALSE;
232+
zend_argument_value_error(1, "must be one of IntlTimeZone::TYPE_ANY,"
233+
" IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION");
234+
RETURN_THROWS();
234235
}
235236

236237
if (!arg3isnull) {
237-
if (UNEXPECTED(offset_arg < (zend_long)INT32_MIN || offset_arg > (zend_long)INT32_MAX)) {
238-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
239-
"offset out of bounds");
240-
RETURN_FALSE;
238+
if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(offset_arg))) {
239+
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
240+
RETURN_THROWS();
241241
}
242-
offset = (int32_t)offset_arg;
242+
offset = static_cast<int32_t>(offset_arg);
243243
offsetp = &offset;
244244
} //else leave offsetp NULL
245245

0 commit comments

Comments
 (0)