Skip to content

Commit

Permalink
vcard: Fix whitespace handling in line cont's (#9637)
Browse files Browse the repository at this point in the history
* vcard: Fix whitespace handling in line cont's

Previously, multiple whitespace characters at the start of a
continuation line would all be dropped, instead of only the first one.

Also,
 - restrict line continuation characters to SPACE and TAB.

Note that, like before, this identifies the CR (`\r`) character with the
empty string, and thereby notably does not require a CRLF (`\r\n`)
sequence (which is mandated by RFCs 2426, 2425) for line termination
(i.e., `\n` suffices).

Fixes: Bug 1 of issue #9593.

* vcard: Add test for #9593/1

* Fix coding style
  • Loading branch information
respiranto authored and alecpl committed Sep 18, 2024
1 parent 602a989 commit ffb2cf7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions program/lib/Roundcube/rcube_vcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ public static function rfc2425_fold($val)
private static function vcard_decode($vcard)
{
// Perform RFC2425 line unfolding and split lines
$vcard = preg_replace(["/\r/", "/\n\s+/"], '', $vcard);
$lines = explode("\n", $vcard);
$vcard = str_replace(["\r", "\n ", "\n\t"], '', $vcard);
$lines = explode("\n", $vcard);
$result = [];

for ($i=0; $i < count($lines); $i++) {
Expand Down Expand Up @@ -1013,8 +1013,8 @@ private static function detect_encoding($string)
// This will for example exclude photos

// Perform RFC2425 line unfolding and split lines
$string = preg_replace(["/\r/", "/\n\s+/"], '', $string);
$lines = explode("\n", $string);
$string = str_replace(["\r", "\n ", "\n\t"], '', $string);
$lines = explode("\n", $string);
$string = '';

for ($i = 0, $len = count($lines); $i < $len; $i++) {
Expand Down
22 changes: 22 additions & 0 deletions tests/Framework/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ function test_parse_six()
$this->assertCount(1, $result['address:work'], "ITEM1.-prefixed entry");
}

/**
* Extra whitespace at start of continuation line (#9593/1).
*/
public function test_parse_continuation_line_with_initial_whitespace()
{
$vcard_string = <<<'EOF'
BEGIN:VCARD
VERSION:3.0
N:Doe;Jane;;;
FN:Jane Doe
NOTE:an
example
END:VCARD
EOF;

$vcard = new \rcube_vcard(str_replace("\n", "\r\n", $vcard_string) . "\r\n");

$result = $vcard->get_assoc();

$this->assertSame('an example', $result['notes'][0]);
}

function test_import()
{
$input = file_get_contents($this->_srcpath('apple.vcf'));
Expand Down

0 comments on commit ffb2cf7

Please sign in to comment.