[Pkg-owncloud-commits] [php-sabre-vobject] 22/46: Always encode VALUE=URI for PHOTO and URL properties.

David Prévot taffit at moszumanska.debian.org
Thu Dec 10 02:12:39 UTC 2015


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

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

commit 84361b13a27f1cb97c4b02c19f543614697fd5ee
Author: Evert Pot <me at evertpot.com>
Date:   Wed Nov 25 22:00:40 2015 -0500

    Always encode VALUE=URI for PHOTO and URL properties.
    
    Fixes #227
    Fixes #235
---
 CHANGELOG.md                       |  2 ++
 lib/Property.php                   |  2 +-
 lib/Property/Uri.php               | 24 ++++++++++++++++++++++++
 tests/VObject/Parser/JsonTest.php  |  2 +-
 tests/VObject/Property/UriTest.php | 27 +++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index cafd124..6cb7468 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ ChangeLog
 * #265: Using the new `InvalidDataException` in place of
   `InvalidArgumentException` and `LogicException` in all places where we fail
   because there was something wrong with input data.
+* #227: Always add `VALUE=URI` to `PHOTO` properties.
+* #235: Always add `VALUE=URI` to `URL` properties.
 
 
 4.0.0-alpha2 (2015-09-04)
diff --git a/lib/Property.php b/lib/Property.php
index cb05d2a..cb57f8e 100644
--- a/lib/Property.php
+++ b/lib/Property.php
@@ -238,7 +238,7 @@ abstract class Property extends Node {
         $str = $this->name;
         if ($this->group) $str = $this->group . '.' . $this->name;
 
-        foreach ($this->parameters as $param) {
+        foreach ($this->parameters() as $param) {
 
             $str .= ';' . $param->serialize();
 
diff --git a/lib/Property/Uri.php b/lib/Property/Uri.php
index a997f32..e4d63bc 100644
--- a/lib/Property/Uri.php
+++ b/lib/Property/Uri.php
@@ -3,6 +3,7 @@
 namespace Sabre\VObject\Property;
 
 use Sabre\VObject\Property;
+use Sabre\VObject\Parameter;
 
 /**
  * URI property.
@@ -38,6 +39,29 @@ class Uri extends Text {
     }
 
     /**
+     * Returns an iterable list of children.
+     *
+     * @return array
+     */
+    function parameters() {
+
+        $parameters = parent::parameters();
+        if (!isset($parameters['VALUE']) && in_array($this->name, ['URL', 'PHOTO'])) {
+            // If we are encoding a URI value, and this URI value has no
+            // VALUE=URI parameter, we add it anyway.
+            //
+            // This is not required by any spec, but both Apple iCal and Apple
+            // AddressBook (at least in version 10.8) will trip over this if
+            // this is not set, and so it improves compatibility.
+            //
+            // See Issue #227 and #235
+            $parameters['VALUE'] = new Parameter($this->root, 'VALUE', 'URI');
+        }
+        return $parameters;
+
+    }
+
+    /**
      * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
      *
      * This has been 'unfolded', so only 1 line will be passed. Unescaping is
diff --git a/tests/VObject/Parser/JsonTest.php b/tests/VObject/Parser/JsonTest.php
index 58f02c1..1814dde 100644
--- a/tests/VObject/Parser/JsonTest.php
+++ b/tests/VObject/Parser/JsonTest.php
@@ -331,7 +331,7 @@ ATTENDEE;CN=Dominik;PARTSTAT=DECLINED:mailto:dominik at example.org
 GEO:51.96668;7.61876
 SEQUENCE:5
 FREEBUSY:20130526T210213/PT1H,20130626T120000/20130626T130000
-URL:http://example.org/
+URL;VALUE=URI:http://example.org/
 TZOFFSETFROM:+0500
 RRULE:FREQ=WEEKLY;BYDAY=MO,TU
 X-BOOL;VALUE=BOOLEAN:TRUE
diff --git a/tests/VObject/Property/UriTest.php b/tests/VObject/Property/UriTest.php
new file mode 100644
index 0000000..2c44d88
--- /dev/null
+++ b/tests/VObject/Property/UriTest.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Sabre\VObject\Property;
+
+use Sabre\VObject\Reader;
+
+class UriTest extends \PHPUnit_Framework_TestCase {
+
+    function testAlwaysEncodeUriVCalendar() {
+
+        // Apple iCal has issues with URL properties that don't have
+        // VALUE=URI specified. We added a workaround to vobject that
+        // ensures VALUE=URI always appears for these.
+        $input = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+URL:http://example.org/
+END:VEVENT
+END:VCALENDAR
+ICS;
+        $output = Reader::read($input)->serialize();
+        $this->assertContains('URL;VALUE=URI:http://example.org/', $output);
+
+    }
+
+}

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



More information about the Pkg-owncloud-commits mailing list