From 2888478dfab666f28b70e59de7dfc2ec49a190e5 Mon Sep 17 00:00:00 2001 From: dpi <danph@81431.no-reply.drupal.org> Date: Sat, 29 Jan 2022 15:21:22 +0000 Subject: [PATCH] Issue #3074723 by dpi, jibran: Better boundary check in getHelper --- src/Plugin/Field/FieldType/DateRecurItem.php | 6 +++++- tests/src/Kernel/DateRecurFieldItemTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Plugin/Field/FieldType/DateRecurItem.php b/src/Plugin/Field/FieldType/DateRecurItem.php index 0cb8307..6abb79f 100644 --- a/src/Plugin/Field/FieldType/DateRecurItem.php +++ b/src/Plugin/Field/FieldType/DateRecurItem.php @@ -419,8 +419,12 @@ class DateRecurItem extends DateRangeItem { return $this->helper; } + $timeZoneString = $this->timezone; + if (empty($timeZoneString)) { + throw new DateRecurHelperArgumentException('Missing time zone'); + } + try { - $timeZoneString = $this->timezone; // If its not a string then cast it so a TypeError is not thrown. An empty // string will cause the exception to be thrown. $timeZone = new \DateTimeZone(is_string($timeZoneString) ? $timeZoneString : ''); diff --git a/tests/src/Kernel/DateRecurFieldItemTest.php b/tests/src/Kernel/DateRecurFieldItemTest.php index e1844eb..78bea69 100644 --- a/tests/src/Kernel/DateRecurFieldItemTest.php +++ b/tests/src/Kernel/DateRecurFieldItemTest.php @@ -224,7 +224,7 @@ class DateRecurFieldItemTest extends KernelTestBase { ], ]; $this->expectException(DateRecurHelperArgumentException::class); - $this->expectExceptionMessage('Invalid time zone'); + $this->expectExceptionMessage('Missing time zone'); $entity->dr[0]->getHelper(); } -- GitLab