Skip to content

Commit

Permalink
Merge pull request #658 from phil-davis/issue-657
Browse files Browse the repository at this point in the history
throw ParseException when null input is provided
  • Loading branch information
phil-davis authored May 27, 2024
2 parents 254f85d + 5d7ca00 commit 227f681
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Parser/MimeDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public function parse($input = null, int $options = 0): ?Document
$this->setInput($input);
}

if (!\is_resource($this->input)) {
// Null was passed as input, but there was no existing input buffer
// There is nothing to parse.
throw new ParseException('No input provided to parse');
}

if (0 !== $options) {
$this->options = $options;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/VObject/Parser/MimeDirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public function testDecodeUnsupportedInlineCharset(): void
$mimeDir->parse($vcard);
}

public function provideEmptyParserInput(): array
{
return [
[null, 'No input provided to parse'],
['', 'End of document reached prematurely'],
];
}

/**
* @dataProvider provideEmptyParserInput
*/
public function testParseEmpty($input, $expectedExceptionMessage): void
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage($expectedExceptionMessage);
$mimeDir = new MimeDir();
$mimeDir->parse($input);
}

public function testDecodeWindows1252(): void
{
$vcard = <<<VCF
Expand Down

0 comments on commit 227f681

Please sign in to comment.