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
12 changes: 12 additions & 0 deletions lib/Property/FlatText.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sabre\VObject\Property;

use Sabre\VObject\InvalidDataException;
use Sabre\VObject\Parser\MimeDir;

/**
* FlatText property.
Expand Down Expand Up @@ -31,6 +32,17 @@ class FlatText extends Text
*/
public string $delimiter = ',';

/**
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
*
* A flat text holds a single value: as said above, unescaped commas are
* not delimiters, so the value is not split.
*/
public function setRawMimeDirValue(string $val): void
{
$this->setValue(MimeDir::unescapeValue($val, ''));
}

/**
* Sets the value as a quoted-printable encoded string.
*
Expand Down
15 changes: 13 additions & 2 deletions tests/VObject/LineFoldingIssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ public function testRead(): void
$event = <<<ICS
BEGIN:VCALENDAR\r
BEGIN:VEVENT\r
DESCRIPTION:TEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\nTEST\\nTEST, TEST\r
DESCRIPTION:TEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\nTEST\\nTEST\\, TEST\r
END:VEVENT\r
END:VCALENDAR\r

ICS;

$expected = <<<ICS
BEGIN:VCALENDAR\r
BEGIN:VEVENT\r
DESCRIPTION:TEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\n \\n\\nTEST\\n\\nTEST\\nTEST\\, TES\r
T\r
END:VEVENT\r
END:VCALENDAR\r

ICS;

$obj = Reader::read($event);
self::assertEquals($event, $obj->serialize());
self::assertEquals("TEST\n\n \n\nTEST\n\n \n\nTEST\n\n \n\nTEST\n\nTEST\nTEST, TEST", $obj->VEVENT->DESCRIPTION->getValue());
self::assertEquals($expected, $obj->serialize());
}
}
45 changes: 45 additions & 0 deletions tests/VObject/Property/FlatTextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Sabre\VObject\Property;

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

class FlatTextTest extends TestCase
{
public function testUnescapedCommaDoesNotSplitTheValue(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nNOTE:Line 1\\nLine 2, and more\r\nEND:VCARD\r\n");

self::assertEquals(['Line 1'."\n".'Line 2, and more'], $vcard->NOTE->getParts());
self::assertEquals('Line 1'."\n".'Line 2, and more', $vcard->NOTE->getValue());
}

public function testEscapedCommaIsUnescaped(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nNOTE:Line 1\\nLine 2\\, and more\r\nEND:VCARD\r\n");

self::assertEquals('Line 1'."\n".'Line 2, and more', $vcard->NOTE->getValue());
}

public function testICalendarText(): void
{
$vcal = Reader::read("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDESCRIPTION:Agenda:\\n1. Budget, staffing\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");

self::assertEquals('Agenda:'."\n".'1. Budget, staffing', $vcal->VEVENT->DESCRIPTION->getValue());
}

public function testJCardHasASingleValue(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Doe, Jane\r\nEND:VCARD\r\n");

self::assertEquals(['fn', new \stdClass(), 'text', 'Doe, Jane'], $vcard->FN->jsonSerialize());
}

public function testUnescapedCommaIsEscapedOnWrite(): void
{
$vcard = Reader::read("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Doe, Jane\r\nEND:VCARD\r\n");

self::assertEquals("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Doe\\, Jane\r\nEND:VCARD\r\n", $vcard->serialize());
}
}