Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ $specifications = [
'P1DT0S',
'2000-01-01T00:00:00Z',
'2000-01-01T00:00:00Z/PT1H',

"PT5S\0garbage",
"PT5S\0",
"\0PT5S",
];

foreach ($specifications as $specification) {
printf("%-25s: ", $specification);
printf("%-25s: ", addcslashes($specification, "\0"));

try {
echo f(Time\Duration::fromIso8601DurationString($specification)), PHP_EOL;
Expand Down Expand Up @@ -72,3 +76,6 @@ P1M : Time\TimeException: The ISO 8601 duration string may
P1DT0S : Time\TimeException: The ISO 8601 duration string may only contain the time (T) aspect
2000-01-01T00:00:00Z : Time\TimeException: The ISO 8601 duration string is missing the period (P) aspect
2000-01-01T00:00:00Z/PT1H: Time\TimeException: The ISO 8601 duration string may only contain the period (P) aspect
PT5S\000garbage : Time\TimeException: The ISO 8601 duration string could not be parsed
PT5S\000 : Time\TimeException: The ISO 8601 duration string could not be parsed
\000PT5S : Time\TimeException: The ISO 8601 duration string could not be parsed
5 changes: 5 additions & 0 deletions ext/date/time_duration.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ PHP_METHOD(Time_Duration, fromIso8601DurationString)
Z_PARAM_STR(specification);
ZEND_PARSE_PARAMETERS_END();

if (zend_str_has_nul_byte(specification)) {
throw_timelib_error(TIMELIB_ERROR_ISO8601_DURATION_PARSE_FAILURE);
RETURN_THROWS();
}

int error;
timelib_duration *d = timelib_duration_create_from_iso8601string(ZSTR_VAL(specification), &error);
if (error != TIMELIB_ERROR_NO_ERROR) {
Expand Down
Loading