Skip to content

Commit 56ee28a

Browse files
kristoffermollerhojphil-davis
authored andcommitted
Improve check for empty property names
Specfically avoid the property name "0" crashes the parser with a 'LogicException: This code should not be reachable'
1 parent 1e9b816 commit 56ee28a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/Parser/MimeDir.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ protected function readProperty($line)
417417
$property['value'] = $match['propValue'];
418418
continue;
419419
}
420-
if (isset($match['name']) && $match['name']) {
420+
if (isset($match['name']) && 0 < strlen($match['name'])) {
421421
$property['name'] = strtoupper($match['name']);
422422
continue;
423423
}
@@ -430,7 +430,7 @@ protected function readProperty($line)
430430
if (is_null($property['value'])) {
431431
$property['value'] = '';
432432
}
433-
if (!$property['name']) {
433+
if (!isset($property['name']) || 0 == strlen($property['name'])) {
434434
if ($this->options & self::OPTION_IGNORE_INVALID_LINES) {
435435
return false;
436436
}

tests/VObject/Parser/MimeDirTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,21 @@ public function provideBrokenVCalendar()
263263
EOF
264264
]];
265265
}
266+
267+
public function testPropertyName0(): void
268+
{
269+
$iCal = <<<EOF
270+
BEGIN:VCALENDAR
271+
VERSION:2.0
272+
PRODID:PRODID
273+
BEGIN:VEVENT
274+
0:test
275+
END:VEVENT
276+
END:VCALENDAR
277+
EOF;
278+
279+
$mimeDir = new MimeDir();
280+
$vevent = $mimeDir->parse($iCal);
281+
self::assertEquals('test', $vevent->VEVENT->{0}->getValue());
282+
}
266283
}

0 commit comments

Comments
 (0)