[Pkg-owncloud-commits] [php-sabredav] 08/29: Return vCard exactly from storage if we don't need to convert.

David Prévot taffit at moszumanska.debian.org
Fri Jul 8 00:24:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit e25f1bb1b88604477b358ad13bc7b7979e2c4f99
Author: Evert Pot <me at evertpot.com>
Date:   Fri May 20 23:45:06 2016 -0400

    Return vCard exactly from storage if we don't need to convert.
    
    Fixes #834.
---
 CHANGELOG.md                         |  2 ++
 lib/CardDAV/Plugin.php               | 56 +++++++++++++++++++++++-------------
 tests/Sabre/CardDAV/MultiGetTest.php |  2 +-
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 237fbfa..a4173f6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ ChangeLog
 -------------------------
 
 * #833: Calendars throw exceptions when the sharing plugin is not enabled.
+* #834: Return vCards exactly as they were stored if we don't need to convert
+  in between versions.
 
 
 3.2.0-alpha1 (2016-05-09)
diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php
index dc1eae8..0507df1 100644
--- a/lib/CardDAV/Plugin.php
+++ b/lib/CardDAV/Plugin.php
@@ -843,33 +843,49 @@ class Plugin extends DAV\ServerPlugin {
     /**
      * Converts a vcard blob to a different version, or jcard.
      *
-     * @param string $data
+     * @param string|resource $data
      * @param string $target
      * @return string
      */
     protected function convertVCard($data, $target) {
 
-        $data = VObject\Reader::read($data);
-        switch ($target) {
-            default :
-            case 'vcard3' :
-                $data = $data->convert(VObject\Document::VCARD30);
-                $newResult = $data->serialize();
-                break;
-            case 'vcard4' :
-                $data = $data->convert(VObject\Document::VCARD40);
-                $newResult = $data->serialize();
-                break;
-            case 'jcard' :
-                $data = $data->convert(VObject\Document::VCARD40);
-                $newResult = json_encode($data->jsonSerialize());
-                break;
-
+        if (is_resource($data)) {
+            $data = stream_get_contents($data);
         }
-        // Destroy circular references to PHP will GC the object.
-        $data->destroy();
+        $input = VObject\Reader::read($data);
+        $output = null;
+        try {
 
-        return $newResult;
+            switch ($target) {
+                default :
+                case 'vcard3' :
+                    if ($input->getDocumentType() === VObject\Document::VCARD30) {
+                        // Do nothing
+                        return $data;
+                    }
+                    $output = $input->convert(VObject\Document::VCARD30);
+                    return $output->serialize();
+                case 'vcard4' :
+                    if ($input->getDocumentType() === VObject\Document::VCARD40) {
+                        // Do nothing
+                        return $data;
+                    }
+                    $output = $input->convert(VObject\Document::VCARD40);
+                    return $output->serialize();
+                case 'jcard' :
+                    $output = $input->convert(VObject\Document::VCARD40);
+                    return json_encode($output);
+
+            }
+
+        } finally {
+
+            // Destroy circular references to PHP will GC the object.
+            $input->destroy();
+            if (!is_null($output)) {
+                $output->destroy();
+            }
+        }
 
     }
 
diff --git a/tests/Sabre/CardDAV/MultiGetTest.php b/tests/Sabre/CardDAV/MultiGetTest.php
index d6cad79..d79239d 100644
--- a/tests/Sabre/CardDAV/MultiGetTest.php
+++ b/tests/Sabre/CardDAV/MultiGetTest.php
@@ -45,7 +45,7 @@ class MultiGetTest extends AbstractPluginTest {
             '/addressbooks/user1/book1/card1' => [
                 200 => [
                     '{DAV:}getetag'                                => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
-                    '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nEND:VCARD\r\n",
+                    '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
                 ]
             ]
         ], $result);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list