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(' ', '')); }