From 5bcc03f9d16ea0721dd8262304234b19a2a38348 Mon Sep 17 00:00:00 2001 From: Daniel Waxweiler Date: Sun, 10 Nov 2024 09:46:26 +0100 Subject: [PATCH] handle location being null --- source/changelog.txt | 1 + source/includes/Formatter.php | 2 +- tests/FormatterTest.php | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/changelog.txt b/source/changelog.txt index ef00277..8e3a59c 100644 --- a/source/changelog.txt +++ b/source/changelog.txt @@ -10,6 +10,7 @@ #### Fixed - Mark event-related data as non-translatable within plugin - Add version number to script registration to break browser caching +- Handle location being null #### Security ### [1.2.0] diff --git a/source/includes/Formatter.php b/source/includes/Formatter.php index 783df52..8386e7d 100644 --- a/source/includes/Formatter.php +++ b/source/includes/Formatter.php @@ -26,7 +26,7 @@ final class Formatter return $dateText; } - public static function format_location(string $description, string $locality): string { + public static function format_location(string $description, ?string $locality): string { $location = ''; if ($description && trim($description)) { $location .= trim($description); diff --git a/tests/FormatterTest.php b/tests/FormatterTest.php index 56ed230..1516080 100644 --- a/tests/FormatterTest.php +++ b/tests/FormatterTest.php @@ -42,6 +42,10 @@ final class FormatterTest extends PHPUnit\Framework\TestCase $this->assertSame('a', Formatter::format_location('a', '')); } + public function testLocationFormatDescriptionOnlyWithNull(): void { + $this->assertSame('a', Formatter::format_location('a', null)); + } + public function testLocationFormatDescriptionWithSpaceOnly(): void { $this->assertSame('', Formatter::format_location(' ', '')); }