From 37372785ff950ea086727d1f38911f2a3acbd5c0 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Sat, 4 May 2024 17:52:01 +0300 Subject: [PATCH] Handle empty Yaml frontmatter Bug: #82 --- src/Page.php | 2 +- tests/PageTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Page.php b/src/Page.php index d180da6..bd04f71 100644 --- a/src/Page.php +++ b/src/Page.php @@ -158,7 +158,7 @@ private function parseContents(): array ); $parsedMetadata = $defaultMetadata; } - $metadata = array_merge($defaultMetadata, $parsedMetadata); + $metadata = array_merge($defaultMetadata, $parsedMetadata ?? []); $body = substr($contents, $frontmatterClosePos + $hyphenCount); } else { $metadata = $defaultMetadata; diff --git a/tests/PageTest.php b/tests/PageTest.php index 2d982e2..8d763a2 100644 --- a/tests/PageTest.php +++ b/tests/PageTest.php @@ -165,6 +165,11 @@ public function provideWriting(): array ['template' => 'lorem'], 'Ipsum.', ], + 'empty Yaml and no body' => [ + "---\n---\n", + ['template' => 'index'], + '', + ], ]; } }