1
0
Fork 0
mirror of synced 2024-09-30 17:26:48 +13:00

Ensure empty datetimes are 0 in 0.15 response

Because empty datetimes are invalid, strtotime returned false so the
response was false rather than 0.
This commit is contained in:
Steven Nguyen 2022-09-15 16:16:30 +00:00 committed by Steven
parent 9893bc166a
commit 01f77fa993
2 changed files with 14 additions and 2 deletions

View file

@ -210,7 +210,11 @@ class V15 extends Filter
protected function parseDatetimeAttributes(array $content, array $attributes): array protected function parseDatetimeAttributes(array $content, array $attributes): array
{ {
foreach ($attributes as $attribute) { foreach ($attributes as $attribute) {
if (isset($content[$attribute])) { if (array_key_exists($attribute, $content)) {
if (empty($content[$attribute])) {
$content[$attribute] = 0;
continue;
}
$content[$attribute] = strtotime($content[$attribute]); $content[$attribute] = strtotime($content[$attribute]);
} }
} }

View file

@ -1077,6 +1077,14 @@ class V15Test extends TestCase
'providerAccessTokenExpiry' => 1592981250, 'providerAccessTokenExpiry' => 1592981250,
], ],
], ],
'empty values' => [
[
'providerAccessTokenExpiry' => '',
],
[
'providerAccessTokenExpiry' => 0,
],
],
]; ];
} }
@ -1089,7 +1097,7 @@ class V15Test extends TestCase
$result = $this->filter->parse($content, $model); $result = $this->filter->parse($content, $model);
$this->assertEquals($expected, $result); $this->assertSame($expected, $result);
} }
/** /**