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 committed Sep 18, 2024
1 parent 6b64eab commit 6159ebe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions program/lib/Roundcube/rcube_vcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ 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);
$vcard = str_replace(["\r", "\n ", "\n\t"], '', $vcard);
$lines = explode("\n", $vcard);
$result = [];

Expand Down Expand Up @@ -985,7 +985,7 @@ 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);
$string = str_replace(["\r", "\n ", "\n\t"], '', $string);
$lines = explode("\n", $string);
$string = '';

Expand Down
22 changes: 22 additions & 0 deletions tests/Framework/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ public 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]);
}

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

0 comments on commit 6159ebe

Please sign in to comment.