Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove empty space after colon #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/Parser/MimeDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,20 @@ protected function parseLine(string $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);
}
Comment on lines +230 to +235
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw the exception, for example with 2 empty space. Not sure if we should cover it or let it fails

} 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()
);
}
}
Loading