[Pkg-owncloud-commits] [php-sabredav] 13/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 b4d4e5010ef38ee3da006d3e2070f7f7c813d78a
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                         |  7 +++++
 lib/CardDAV/Plugin.php               | 56 +++++++++++++++++++++++-------------
 tests/Sabre/CardDAV/MultiGetTest.php | 16 +++++------
 3 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f719c8e..4db4a9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,13 @@
 ChangeLog
 =========
 
+3.1.4 (2016-??-??)
+------------------
+
+* #834: Backport from `master`: Return vCards exactly as they were stored if
+  we don't need to convert in between versions.
+
+
 3.1.3 (2016-04-06)
 ------------------
 
diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php
index b8bded0..70af69f 100644
--- a/lib/CardDAV/Plugin.php
+++ b/lib/CardDAV/Plugin.php
@@ -803,33 +803,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 b0ee458..2f0651c 100644
--- a/tests/Sabre/CardDAV/MultiGetTest.php
+++ b/tests/Sabre/CardDAV/MultiGetTest.php
@@ -41,14 +41,14 @@ class MultiGetTest extends AbstractPluginTest {
 
         $result = $client->parseMultiStatus($response->body);
 
-        $this->assertEquals(array(
-            '/addressbooks/user1/book1/card1' => array(
-                200 => array(
-                    '{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",
-                )
-            )
-        ), $result);
+        $this->assertEquals([
+            '/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\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