Skip to content

Commit

Permalink
Merge pull request #41 from caendesilva/patch-1
Browse files Browse the repository at this point in the history
Check if the array key is set before trying to trim it
  • Loading branch information
sebastiandedeyne authored Jun 13, 2024
2 parents be58441 + 1130777 commit cbe67e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ComplexMarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function getBody(): string

protected function trimBody(array $body): array
{
if (trim($body[0]) === '') {
if (isset($body[0]) && trim($body[0]) === '') {
unset($body[0]);
}

Expand Down
14 changes: 13 additions & 1 deletion tests/YamlFrontMatterMarkdownCompatibleParseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function it_separates_the_front_matter_from_the_body()
public function it_leaves_string_without_front_matter_intact()
{
$document = YamlFrontMatter::markdownCompatibleParse(
"Lorem ipsum."
'Lorem ipsum.'
);

$this->assertInstanceOf(Document::class, $document);
Expand Down Expand Up @@ -97,4 +97,16 @@ public function it_can_parse_a_string_with_windows_line_endings()
$this->assertEquals(['foo' => 'bar'], $document->matter());
$this->assertStringContainsString('Lorem ipsum.', $document->body());
}

/** @test */
public function it_can_parse_markdown_file_with_front_matter_and_no_markdown_body()
{
$document = YamlFrontMatter::markdownCompatibleParse(
"---\nfoo: bar\n---"
);

$this->assertInstanceOf(Document::class, $document);
$this->assertEquals(['foo' => 'bar'], $document->matter());
$this->assertEmpty($document->body());
}
}

0 comments on commit cbe67e1

Please sign in to comment.