Skip to content

Commit

Permalink
Merge pull request #87 from ProtonMail/calbe2290
Browse files Browse the repository at this point in the history
[Calendar][CALBE-2290][Feat] added whitelist for illegal values in pa…
  • Loading branch information
chris-szu authored Jun 19, 2023
2 parents d7c313f + aba1a70 commit b7195f2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ abstract class Document extends Component
*/
public static $valueMap = [];

/**
* List of RFC violating values that we allow in parameter value.
* e.g. LOCATION;VALUE=ERROR:some location
*
* @var string[]
*/
private array $allowedIllegalValues = [
'ERROR',
];

/**
* Creates a new document.
*
Expand Down Expand Up @@ -213,7 +223,12 @@ public function createProperty($name, $value = null, array $parameters = null, $
if (isset($parameters['VALUE'])) {
$class = $this->getClassNameForPropertyValue($parameters['VALUE']);
if (is_null($class)) {
throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"');
if (in_array(strtoupper($parameters['VALUE']), $this->allowedIllegalValues, true)) {
unset($parameters['VALUE']);
$class = $this->getClassNameForPropertyName($name);
} else {
throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"');
}
}
} else {
$class = $this->getClassNameForPropertyName($name);
Expand Down
31 changes: 31 additions & 0 deletions tests/VObject/InvalidValueParamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Sabre\VObject;

use PHPUnit\Framework\TestCase;

class InvalidValueParamTest extends TestCase
{
public function testWorkaround()
{
$event = <<<ICS
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTEND;TZID=Europe/Paris:20170530T220000
DTSTAMP:20230317T130521Z
DTSTART;TZID=Europe/Paris:20170530T200000
LAST-MODIFIED:20230316T155811Z
LOCATION;VALUE=ERROR:EXAMPLE
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:AG MP3
UID:0171706E-00F4-4846-8B5F-7FBD474A90AC
END:VEVENT
END:VCALENDAR
ICS;

$doc = Reader::read($event);
$this->assertEquals("LOCATION:EXAMPLE\r\n", $doc->VEVENT->LOCATION->serialize());
}
}

0 comments on commit b7195f2

Please sign in to comment.