From 1fb1758d5933229c0c2900914004990f2ff23ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einhard=20Leichtfu=C3=9F?= Date: Sat, 14 Sep 2024 15:46:01 +0200 Subject: [PATCH 1/3] 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. --- program/lib/Roundcube/rcube_vcard.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program/lib/Roundcube/rcube_vcard.php b/program/lib/Roundcube/rcube_vcard.php index 9552ba5821..8ef581b8b6 100644 --- a/program/lib/Roundcube/rcube_vcard.php +++ b/program/lib/Roundcube/rcube_vcard.php @@ -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 = []; @@ -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 = ''; From 8eae2c3688c6aa5dd28a38b2f1a0cf9c286cdb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einhard=20Leichtfu=C3=9F?= Date: Mon, 16 Sep 2024 19:22:32 +0200 Subject: [PATCH 2/3] vcard: Add test for #9593/1 --- tests/Framework/VCardTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Framework/VCardTest.php b/tests/Framework/VCardTest.php index 4d933ae229..5181fca3fc 100644 --- a/tests/Framework/VCardTest.php +++ b/tests/Framework/VCardTest.php @@ -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_lines = + [ 'BEGIN:VCARD' + , 'VERSION:3.0' + , 'N:Doe;Jane;;;' + , 'FN:Jane Doe' + , 'NOTE:an' + , ' example' + , 'END:VCARD' + ]; + + $vcard = new \rcube_vcard(implode("\r\n", $vcard_lines) . "\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')); From 6999dfa80a5d67b337d7f2db70662d1e1bb35fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einhard=20Leichtfu=C3=9F?= Date: Tue, 17 Sep 2024 19:34:40 +0200 Subject: [PATCH 3/3] Fix coding style --- tests/Framework/VCardTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Framework/VCardTest.php b/tests/Framework/VCardTest.php index 5181fca3fc..504035e9bc 100644 --- a/tests/Framework/VCardTest.php +++ b/tests/Framework/VCardTest.php @@ -104,17 +104,17 @@ public function test_parse_six() */ public function test_parse_continuation_line_with_initial_whitespace() { - $vcard_lines = - [ 'BEGIN:VCARD' - , 'VERSION:3.0' - , 'N:Doe;Jane;;;' - , 'FN:Jane Doe' - , 'NOTE:an' - , ' example' - , 'END:VCARD' - ]; - - $vcard = new \rcube_vcard(implode("\r\n", $vcard_lines) . "\r\n"); + $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();