From 5d2e6cbd3bd8e8605640569dcc57fbc0369db96d Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Tue, 12 Jul 2022 17:08:55 +0200 Subject: [PATCH] Ignore multiple same parameter-values 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. --- lib/Parser/MimeDir.php | 3 +++ tests/VObject/Parser/MimeDirTest.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php index db0f81531..e9cc75bdc 100644 --- a/lib/Parser/MimeDir.php +++ b/lib/Parser/MimeDir.php @@ -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], diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php index 183c9ce4c..f46411ab7 100644 --- a/tests/VObject/Parser/MimeDirTest.php +++ b/tests/VObject/Parser/MimeDirTest.php @@ -145,4 +145,26 @@ public function testCaseInsensitiveInlineCharset() $this->assertEquals('Euro', $vcard->FN->getValue()); $this->assertEquals('Test2', $vcard->N->getValue()); } + + public function testParsingTwiceSameContent() + { + $card = <<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()); + } }