Loading core/lib/Drupal/Component/Datetime/DateTimePlus.php +9 −3 Original line number Diff line number Diff line Loading @@ -568,14 +568,20 @@ public static function prepareArray($array, $force_valid_date = FALSE) { * TRUE if the datetime parts contain valid values, otherwise FALSE. */ public static function checkArray($array) { $valid_date = FALSE; $valid_time = TRUE; // Check for a valid date using checkdate(). Only values that // meet that test are valid. An empty value, either a string or a 0, is not // a valid value. if (!empty($array['year']) && !empty($array['month']) && !empty($array['day'])) { $valid_date = checkdate($array['month'], $array['day'], $array['year']); foreach (['year', 'month', 'day'] as $key) { if ( empty($array[$key]) || filter_var($array[$key], FILTER_VALIDATE_INT) === FALSE ) { return FALSE; } } $valid_date = checkdate($array['month'], $array['day'], $array['year']); // Testing for valid time is reversed. Missing time is OK, // but incorrect values are not. foreach (['hour', 'minute', 'second'] as $key) { Loading core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -631,6 +631,18 @@ public static function providerTestCheckArray(): array { ], 'Missing day' => [['year' => 2059, 'month' => 1, 'second' => 1], FALSE], 'Zero day' => [['year' => 2059, 'month' => 1, 'day' => 0], FALSE], 'Non-numeric year' => [ ['year' => 'invalid', 'month' => 11, 'day' => 2], FALSE, ], 'Non-numeric month' => [ ['year' => 2025, 'month' => 'invalid', 'day' => 2], FALSE, ], 'Non-numeric day' => [ ['year' => 2025, 'month' => 11, 'day' => 'invalid'], FALSE, ], ]; } Loading Loading
core/lib/Drupal/Component/Datetime/DateTimePlus.php +9 −3 Original line number Diff line number Diff line Loading @@ -568,14 +568,20 @@ public static function prepareArray($array, $force_valid_date = FALSE) { * TRUE if the datetime parts contain valid values, otherwise FALSE. */ public static function checkArray($array) { $valid_date = FALSE; $valid_time = TRUE; // Check for a valid date using checkdate(). Only values that // meet that test are valid. An empty value, either a string or a 0, is not // a valid value. if (!empty($array['year']) && !empty($array['month']) && !empty($array['day'])) { $valid_date = checkdate($array['month'], $array['day'], $array['year']); foreach (['year', 'month', 'day'] as $key) { if ( empty($array[$key]) || filter_var($array[$key], FILTER_VALIDATE_INT) === FALSE ) { return FALSE; } } $valid_date = checkdate($array['month'], $array['day'], $array['year']); // Testing for valid time is reversed. Missing time is OK, // but incorrect values are not. foreach (['hour', 'minute', 'second'] as $key) { Loading
core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -631,6 +631,18 @@ public static function providerTestCheckArray(): array { ], 'Missing day' => [['year' => 2059, 'month' => 1, 'second' => 1], FALSE], 'Zero day' => [['year' => 2059, 'month' => 1, 'day' => 0], FALSE], 'Non-numeric year' => [ ['year' => 'invalid', 'month' => 11, 'day' => 2], FALSE, ], 'Non-numeric month' => [ ['year' => 2025, 'month' => 'invalid', 'day' => 2], FALSE, ], 'Non-numeric day' => [ ['year' => 2025, 'month' => 11, 'day' => 'invalid'], FALSE, ], ]; } Loading