Skip to content

Commit

Permalink
Ignore multiple same parameter-values
Browse files Browse the repository at this point in the history
Sometimes it seems like parameters can be added multiple times with
the same value. Besides not making any sense (and partially being
not allowed in the first place) this will also possibly break the
further process of parsing an icalendar file.

This modification adds a shortcut when the last parameter-value and the
current parameter value are exactly the same. In that case the new
value is ignored and only the old value will be used.

The use-case - as documented in the test - is that there seem to be
icalendar files that contain the following content:

    DTSTART;VALUE=DATE;VALUE=DATE:20220612

While that seems to violate the RFC it is not seen as a violation in
the icalendar validator at https://icalendar.org/validator.html and
as it can also be imported by other calendaring systems it looks like
this should at least not break the parser.
  • Loading branch information
heiglandreas committed Jul 12, 2022
1 parent b8a44ea commit 5d2e6cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Parser/MimeDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ protected function readProperty($line)
$property['parameters'][$lastParam] = $value;
} elseif (is_array($property['parameters'][$lastParam])) {
$property['parameters'][$lastParam][] = $value;
} elseif ($property['parameters'][$lastParam] === $value) {
// When the current value of the parameter is the same as the
// new one, then we can leave the current parameter as it is.
} else {
$property['parameters'][$lastParam] = [
$property['parameters'][$lastParam],
Expand Down
22 changes: 22 additions & 0 deletions tests/VObject/Parser/MimeDirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,26 @@ public function testCaseInsensitiveInlineCharset()
$this->assertEquals('Euro', $vcard->FN->getValue());
$this->assertEquals('Test2', $vcard->N->getValue());
}

public function testParsingTwiceSameContent()
{
$card = <<<EOF
BEGIN:VCALENDAR
VERSION:2.0
PRODID:icalendar-ruby
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Designated Interpreters Calendar (Canvas)
X-WR-CALDESC:Calendar events for the user\, Designated Interpreters
BEGIN:VEVENT
DTSTART;VALUE=DATE;VALUE=DATE:20220612
END:VEVENT
END:VCALENDAR
EOF;

$mimeDir = new MimeDir();
$vcard = $mimeDir->parse($card);
// we can do a simple assertion here. As long as we don't get an exception, everything is thing
$this->assertEquals('20220612', $vcard->VEVENT->DTSTART->getValue());
}
}

0 comments on commit 5d2e6cb

Please sign in to comment.