Skip to content

Commit c8ef5fd

Browse files
authored
Merge pull request #674 from heiglandreas/allow-unknown-value-data-types
Allow unknown value data types for VALUE
2 parents 2fcc82e + 1f22f4a commit c8ef5fd

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

lib/Document.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,30 @@ public function createProperty(string $name, $value = null, ?array $parameters =
180180

181181
$class = null;
182182

183+
// If a VALUE parameter is supplied, we have to use that
184+
// According to https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.20
185+
// If the property's value is the default value type, then this
186+
// parameter need not be specified. However, if the property's
187+
// default value type is overridden by some other allowable value
188+
// type, then this parameter MUST be specified.
189+
if (!$valueType) {
190+
$valueType = $parameters['VALUE'] ?? null;
191+
}
192+
183193
if ($valueType) {
184194
// The valueType argument comes first to figure out the correct
185195
// class.
186196
$class = $this->getClassNameForPropertyValue($valueType);
187197
}
188198

199+
// If the value parameter is not set or set to something we do not recognize
200+
// we do not attempt to interpret or parse the datass value as specified in
201+
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.2.20
202+
// So when we so far did not get a class-name, we use the default for the property
189203
if (is_null($class)) {
190-
// If a VALUE parameter is supplied, we should use that.
191-
if (isset($parameters['VALUE'])) {
192-
$class = $this->getClassNameForPropertyValue($parameters['VALUE']);
193-
if (is_null($class)) {
194-
throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"');
195-
}
196-
} else {
197-
$class = $this->getClassNameForPropertyName($name);
198-
}
204+
$class = $this->getClassNameForPropertyName($name);
199205
}
206+
200207
if (is_null($parameters)) {
201208
$parameters = [];
202209
}

tests/VObject/PropertyTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Sabre\VObject\Component\VCalendar;
77
use Sabre\VObject\Component\VCard;
8+
use Sabre\VObject\Property\ICalendar\DateTime;
89

910
class PropertyTest extends TestCase
1011
{
@@ -391,4 +392,18 @@ public function testValidateBadEncodingVCard21(): void
391392
self::assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']);
392393
self::assertEquals(3, $result[0]['level']);
393394
}
395+
396+
public function testUnknownValuesWillBeIgnored(): void
397+
{
398+
$cal = new VCalendar();
399+
$property = $cal->createProperty('DTSTAMP', '20240101T000000Z', ['VALUE' => 'DATETIME']);
400+
401+
self::assertEquals("DTSTAMP;VALUE=DATETIME:20240101T000000Z\r\n", $property->serialize());
402+
403+
self::assertInstanceOf(DateTime::class, $property);
404+
self::assertCount(1, $property->parameters());
405+
self::assertInstanceOf(Parameter::class, $property->parameters['VALUE']);
406+
self::assertEquals('VALUE', $property->parameters['VALUE']->name);
407+
self::assertEquals('DATETIME', $property->parameters['VALUE']->getValue());
408+
}
394409
}

0 commit comments

Comments
 (0)