Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Component/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ public function getClassNameForPropertyName(string $propertyName): string
return VObject\Property\Uri::class;
}

// In vCard 4, KEY and SOUND are URIs by default too (RFC 6350, sections
// 6.7.5 and 6.8.1), not text.
if (in_array($propertyName, ['KEY', 'SOUND'], true) && self::VCARD40 === $this->getDocumentType()) {
return VObject\Property\Uri::class;
}

return $className;
}
}
44 changes: 44 additions & 0 deletions tests/VObject/Component/VCardKeySoundTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Sabre\VObject\Component;

use PHPUnit\Framework\TestCase;
use Sabre\VObject\Document;
use Sabre\VObject\Property;
use Sabre\VObject\Reader;

class VCardKeySoundTest extends TestCase
{
public function testKeyAndSoundAreUrisInVCard40(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nKEY:https://example.com/key.asc\r\nSOUND:https://example.com/name.wav\r\nEND:VCARD\r\n");

self::assertInstanceOf(Property\Uri::class, $vcard->KEY);
self::assertInstanceOf(Property\Uri::class, $vcard->SOUND);
self::assertEquals(['key', new \stdClass(), 'uri', 'https://example.com/key.asc'], $vcard->KEY->jsonSerialize());
}

public function testATextKeyStaysText(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nKEY;VALUE=text:-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nEND:VCARD\r\n");

self::assertInstanceOf(Property\Text::class, $vcard->KEY);
}

public function testVCard30IsUnchanged(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:3.0\r\nKEY:https://example.com/key.asc\r\nEND:VCARD\r\n");

self::assertInstanceOf(Property\FlatText::class, $vcard->KEY);
}

public function testSoundDataUriConvertsToBinaryInVCard30(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nSOUND:data:audio/wav;base64,UklGRg==\r\nEND:VCARD\r\n");

$converted = $vcard->convert(Document::VCARD30);

self::assertInstanceOf(Property\Binary::class, $converted->SOUND);
self::assertEquals('RIFF', $converted->SOUND->getValue());
}
}
4 changes: 2 additions & 2 deletions tests/VObject/Parser/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ public function testRFC6350Section6Part7Part5(): void
<vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
<vcard>
<sound>
<text>CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com</text>
<uri>CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com</uri>
</sound>
</vcard>
</vcards>
Expand Down Expand Up @@ -2571,7 +2571,7 @@ public function testRFC6350Section6Part8Part1(): void
<text>application/pgp-keys</text>
</mediatype>
</parameters>
<text>ftp://example.com/keys/jdoe</text>
<uri>ftp://example.com/keys/jdoe</uri>
</key>
</vcard>
</vcards>
Expand Down