Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 227f681

Browse files
authoredMay 27, 2024··
Merge pull request #658 from phil-davis/issue-657
throw ParseException when null input is provided
2 parents 254f85d + 5d7ca00 commit 227f681

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎lib/Parser/MimeDir.php

+6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public function parse($input = null, int $options = 0): ?Document
7979
$this->setInput($input);
8080
}
8181

82+
if (!\is_resource($this->input)) {
83+
// Null was passed as input, but there was no existing input buffer
84+
// There is nothing to parse.
85+
throw new ParseException('No input provided to parse');
86+
}
87+
8288
if (0 !== $options) {
8389
$this->options = $options;
8490
}

‎tests/VObject/Parser/MimeDirTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ public function testDecodeUnsupportedInlineCharset(): void
101101
$mimeDir->parse($vcard);
102102
}
103103

104+
public function provideEmptyParserInput(): array
105+
{
106+
return [
107+
[null, 'No input provided to parse'],
108+
['', 'End of document reached prematurely'],
109+
];
110+
}
111+
112+
/**
113+
* @dataProvider provideEmptyParserInput
114+
*/
115+
public function testParseEmpty($input, $expectedExceptionMessage): void
116+
{
117+
$this->expectException(ParseException::class);
118+
$this->expectExceptionMessage($expectedExceptionMessage);
119+
$mimeDir = new MimeDir();
120+
$mimeDir->parse($input);
121+
}
122+
104123
public function testDecodeWindows1252(): void
105124
{
106125
$vcard = <<<VCF

0 commit comments

Comments
 (0)
Please sign in to comment.