Skip to content

Commit 7b1a4e2

Browse files
nyamsprodderickr
authored andcommitted
Fixed bug #77909: DatePeriod::__construct() with invalid recurrence count value
Improve error message on invalid reccurence count Adding test when reccurence is -1
1 parent 6fe75f9 commit 7b1a4e2

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
. Fixed bug #77794 (Incorrect Date header format in built-in server).
1010
(kelunik)
1111

12+
- Date:
13+
. Fixed bug #77909 (DatePeriod::__construct() with invalid recurrence count
14+
value). (Ignace Nyamagana Butera)
15+
1216
- Interbase:
1317
. Fixed bug #72175 (Impossibility of creating multiple connections to
1418
Interbase with php 7.x). (Nikita)

ext/date/php_date.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,6 +4645,10 @@ PHP_METHOD(DatePeriod, __construct)
46454645
dpobj->end = clone;
46464646
}
46474647
}
4648+
4649+
if (dpobj->end == NULL && recurrences < 1) {
4650+
php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences);
4651+
}
46484652

46494653
/* options */
46504654
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
DatePeriod: Test wrong recurrence parameter on __construct
3+
--FILE--
4+
<?php
5+
try {
6+
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
7+
} catch (Exception $exception) {
8+
echo $exception->getMessage(), "\n";
9+
}
10+
11+
try {
12+
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'),-1);
13+
} catch (Exception $exception) {
14+
echo $exception->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECTF--
18+
DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0
19+
DatePeriod::__construct(): The recurrence count '-1' is invalid. Needs to be > 0

0 commit comments

Comments
 (0)