Skip to content

Commit

Permalink
[Calendar][CALBE-2290][Feat] added whitelist for illegal values in pa…
Browse files Browse the repository at this point in the history
…rameter
  • Loading branch information
Christopher Szu authored and Christopher Szu committed Jun 16, 2023
1 parent d7c313f commit d9a20bb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
15 changes: 14 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 @@ -212,7 +222,10 @@ public function createProperty($name, $value = null, array $parameters = null, $
// If a VALUE parameter is supplied, we should use that.
if (isset($parameters['VALUE'])) {
$class = $this->getClassNameForPropertyValue($parameters['VALUE']);
if (is_null($class)) {
if (is_null($class) && 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 {
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:ERROR
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:ERROR\r\n", $doc->VEVENT->LOCATION->serialize());
}
}

0 comments on commit d9a20bb

Please sign in to comment.