Skip to content

Commit 1318bbe

Browse files
committed
Revert exception changes + add test coverage
1 parent 6cbe3b5 commit 1318bbe

7 files changed

+42
-13
lines changed

ext/date/php_date.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,7 @@ PHP_METHOD(DatePeriod, __construct)
41214121
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOl|l", &start, date_ce_interface, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
41224122
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOO|l", &start, date_ce_interface, &interval, date_ce_interval, &end, date_ce_interface, &options) == FAILURE) {
41234123
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|l", &isostr, &isostr_len, &options) == FAILURE) {
4124-
zend_type_error("DatePeriod::__construct() accepts either (DateTimeInterface, DateInterval, int [, int]) OR (DateTimeInterface, DateInterval, DateTime [, int]) OR (string [, int]) as arguments");
4124+
zend_type_error("DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments");
41254125
RETURN_THROWS();
41264126
}
41274127
}
@@ -4131,7 +4131,7 @@ PHP_METHOD(DatePeriod, __construct)
41314131
dpobj->current = NULL;
41324132

41334133
if (isostr) {
4134-
zend_replace_error_handling(EH_THROW, zend_ce_value_error, &error_handling);
4134+
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
41354135
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len);
41364136
zend_restore_error_handling(&error_handling);
41374137
if (EG(exception)) {
@@ -4140,19 +4140,19 @@ PHP_METHOD(DatePeriod, __construct)
41404140

41414141
if (dpobj->start == NULL) {
41424142
zend_string *func = get_active_function_or_method_name();
4143-
zend_value_error("%s(): Argument #1 must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
4143+
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
41444144
zend_string_release(func);
41454145
RETURN_THROWS();
41464146
}
41474147
if (dpobj->interval == NULL) {
41484148
zend_string *func = get_active_function_or_method_name();
4149-
zend_value_error("%s(): Argument #1 must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
4149+
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
41504150
zend_string_release(func);
41514151
RETURN_THROWS();
41524152
}
41534153
if (dpobj->end == NULL && recurrences == 0) {
41544154
zend_string *func = get_active_function_or_method_name();
4155-
zend_value_error("%s(): Argument #1 must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
4155+
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
41564156
zend_string_release(func);
41574157
RETURN_THROWS();
41584158
}
@@ -4194,7 +4194,7 @@ PHP_METHOD(DatePeriod, __construct)
41944194

41954195
if (dpobj->end == NULL && recurrences < 1) {
41964196
zend_string *func = get_active_function_or_method_name();
4197-
zend_value_error("%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
4197+
zend_throw_error(zend_ce_exception, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
41984198
zend_string_release(func);
41994199
RETURN_THROWS();
42004200
}

ext/date/tests/DatePeriod_wrong_constructor.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ try {
1515
}
1616
?>
1717
--EXPECT--
18-
DatePeriod::__construct() accepts either (DateTimeInterface, DateInterval, int [, int]) OR (DateTimeInterface, DateInterval, DateTime [, int]) OR (string [, int]) as arguments
18+
DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments

ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ DatePeriod: Test wrong recurrence parameter on __construct
44
<?php
55
try {
66
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
7-
} catch (ValueError $exception) {
7+
} catch (Exception $exception) {
88
echo $exception->getMessage(), "\n";
99
}
1010

1111
try {
1212
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), -1);
13-
} catch (ValueError $exception) {
13+
} catch (Exception $exception) {
1414
echo $exception->getMessage(), "\n";
1515
}
1616

ext/date/tests/bug44562.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ date_default_timezone_set('Europe/Oslo');
66

77
try {
88
$dp = new DatePeriod('2D');
9-
} catch (ValueError $e) {
9+
} catch (Exception $e) {
1010
echo $e->getMessage(), "\n";
1111
}
1212

ext/date/tests/bug54283.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #54283 (new DatePeriod(NULL) causes crash)
55

66
try {
77
var_dump(new DatePeriod(NULL));
8-
} catch (ValueError $e) {
8+
} catch (Exception $e) {
99
var_dump($e->getMessage());
1010
}
1111

ext/date/tests/date_interval_bad_format_leak.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ try {
1111

1212
try {
1313
$perid = new DatePeriod('P3"D');
14-
} catch (ValueError $e) {
14+
} catch (Exception $e) {
1515
echo $e->getMessage(), "\n";
1616
}
1717

1818
try {
1919
new DatePeriod('2008-03-01T12:00:00Z1');
20-
} catch (ValueError $e) {
20+
} catch (Exception $e) {
2121
echo $e->getMessage(), "\n";
2222
}
2323

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test bad ISO date formats passed to DatePeriod constructor
3+
--FILE--
4+
<?php
5+
6+
try {
7+
$perid = new DatePeriod("R4");
8+
} catch (Exception $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
try {
13+
$perid = new DatePeriod("R4/2012-07-01T00:00:00Z");
14+
} catch (Exception $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
19+
try {
20+
$perid = new DatePeriod("2012-07-01T00:00:00Z/P7D");
21+
} catch (Exception $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
25+
?>
26+
--EXPECT--
27+
DatePeriod::__construct(): ISO interval must contain a start date, "R4" given
28+
DatePeriod::__construct(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given
29+
DatePeriod::__construct(): ISO interval must contain an end date or a recurrence count, "2012-07-01T00:00:00Z/P7D" given

0 commit comments

Comments
 (0)