Skip to content

Commit

Permalink
Remove empty space after colon
Browse files Browse the repository at this point in the history
  • Loading branch information
Ren Xie Liu committed Sep 7, 2023
1 parent 72c81a9 commit 4ea3342
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/Parser/MimeDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,20 @@ protected function parseLine($line)
&& $e instanceof ParseException && str_contains($e->getMessage(), 'Invalid Mimedir file. Line starting at')
&& ($this->options & Reader::OPTION_FIX_UNFOLDING)
) {
// Fix unfolding
$component->remove($prevNode);
$value = $prevNode->getValue() . ' ' . $line . PHP_EOL;
$prevNode->offsetSet('VALUE', $value);
$prevNode->setValue($value);
$component->add($prevNode);
if (preg_match('/[A-Z]\w+; /', $line)) {
$line = preg_replace('/([A-Z]\w+;) /', '$1', $line);
$result = $this->parseLine($line);
if ($result) {
$prevNode = $component->add($result);
}
} else {
// Fix unfolding
$component->remove($prevNode);
$value = $prevNode->getValue() . ' ' . $line . PHP_EOL;
$prevNode->offsetSet('VALUE', $value);
$prevNode->setValue($value);
$component->add($prevNode);
}
continue;
}
throw $e;
Expand Down
27 changes: 27 additions & 0 deletions tests/VObject/Parser/UnfoldingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,31 @@ public function testNotFixUnknownProperty()

$this->assertNotNull($vcard->children()[0]->CONFERENCE->getValue());
}

public function testRemoveEmptySpaceAfterColon(): void
{
$vcard = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Proton AG//AndroidCalendar 2.11.20//EN
BEGIN:VEVENT
SEQUENCE:0
ORGANIZER; CN=Plannert:mailto:noreply@sho.nl
END:VEVENT
END:VCALENDAR
ICS;

$vcard = (new MimeDir())->parse($vcard, Reader::OPTION_FIX_UNFOLDING | Reader::OPTION_FORGIVING);


$this->assertSame(
0,
$vcard->VEVENT->SEQUENCE->getValue()
);

$this->assertSame(
'ORGANIZER;CN=Plannert:mailto:noreply@sho.nl' . "\r\n",
$vcard->VEVENT->ORGANIZER->serialize()
);
}
}

0 comments on commit 4ea3342

Please sign in to comment.