From 85340b7c1f22f6dec5f295ec64fb1fcc0907f92f Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Tue, 12 Jul 2022 17:08:55 +0200 Subject: [PATCH 1/2] 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 | 20 ++++++++++++++++++++ 2 files changed, 23 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..3a0e71c75 100644 --- a/tests/VObject/Parser/MimeDirTest.php +++ b/tests/VObject/Parser/MimeDirTest.php @@ -145,4 +145,24 @@ 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()); + } } From 404e54826d93aba111aa7ef681f1021f3b6c1c47 Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Thu, 14 Jul 2022 13:47:47 +0200 Subject: [PATCH 2/2] Fix a comment --- tests/VObject/Parser/MimeDirTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php index 3a0e71c75..bd31b8159 100644 --- a/tests/VObject/Parser/MimeDirTest.php +++ b/tests/VObject/Parser/MimeDirTest.php @@ -162,7 +162,7 @@ public function testParsingTwiceSameContent() $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 + // we can do a simple assertion here. As long as we don't get an exception, everything is fine $this->assertEquals('20220612', $vcard->VEVENT->DTSTART->getValue()); } }