1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/intl: better errors for IntlTimeZone::createTimeZoneIDEnumeration (#19395)

IntlTimeZone::createTimeZoneIDEnumeration

And convert those to ValueErrors directly as they are bugs
This commit is contained in:
Gina Peter Banyard
2025-08-07 13:52:03 +01:00
committed by GitHub
parent ca5667bc14
commit 43420599f7
3 changed files with 33 additions and 13 deletions

View File

@@ -1,13 +1,16 @@
--TEST--
IntlTimeZone::createTimeZoneIDEnumeration(): errors
IntlTimeZone::createTimeZoneIDEnumeration() invalid zone type
--EXTENSIONS--
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
try {
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(-1));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Warning: IntlTimeZone::createTimeZoneIDEnumeration(): bad zone type in %s on line %d
bool(false)
--EXPECT--
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be one of IntlTimeZone::TYPE_ANY, IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION

View File

@@ -0,0 +1,17 @@
--TEST--
IntlTimeZone::createTimeZoneIDEnumeration() offset out of range
--EXTENSIONS--
intl
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
--FILE--
<?php
try {
var_dump(IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, '', PHP_INT_MAX));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
ValueError: IntlTimeZone::createTimeZoneIDEnumeration(): Argument #1 ($type) must be between -2147483648 and 2147483647

View File

@@ -229,17 +229,17 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL
&& zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "bad zone type");
RETURN_FALSE;
zend_argument_value_error(1, "must be one of IntlTimeZone::TYPE_ANY,"
" IntlTimeZone::TYPE_CANONICAL, or IntlTimeZone::TYPE_CANONICAL_LOCATION");
RETURN_THROWS();
}
if (!arg3isnull) {
if (UNEXPECTED(offset_arg < (zend_long)INT32_MIN || offset_arg > (zend_long)INT32_MAX)) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"offset out of bounds");
RETURN_FALSE;
if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(offset_arg))) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
offset = (int32_t)offset_arg;
offset = static_cast<int32_t>(offset_arg);
offsetp = &offset;
} //else leave offsetp NULL