[Pkg-owncloud-commits] [php-sabre-vobject] 02/07: Ignoring CHARSET except if we're parsing vCard 2.1

David Prévot taffit at moszumanska.debian.org
Tue Jan 12 01:32:33 UTC 2016


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 581ed6c6da37dfbaebd211dd1784524d7c5c35e5
Author: Evert Pot <me at evertpot.com>
Date:   Thu Jan 7 20:05:04 2016 -0500

    Ignoring CHARSET except if we're parsing vCard 2.1
---
 CHANGELOG.md                         |  7 +++++++
 lib/Component/VCard.php              |  5 +++--
 lib/Parser/MimeDir.php               |  3 ++-
 lib/Version.php                      |  2 +-
 tests/VObject/Parser/MimeDirTest.php | 19 +++++++++++++++++--
 5 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 50ab570..e609f52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,13 @@
 ChangeLog
 =========
 
+4.0.2 (????-??-??)
+------------------
+
+* #288: Only decode `CHARSET` if we're reading vCard 2.1. If it appears
+  in any other document, we must ignore it.
+
+
 4.0.1 (2016-01-04)
 ------------------
 
diff --git a/lib/Component/VCard.php b/lib/Component/VCard.php
index b49554e..66bbdd7 100644
--- a/lib/Component/VCard.php
+++ b/lib/Component/VCard.php
@@ -161,8 +161,9 @@ class VCard extends VObject\Document {
                     $this->version = self::VCARD40;
                     break;
                 default :
-                    $this->version = self::UNKNOWN;
-                    break;
+                    // We don't want to cache the version if it's unknown,
+                    // because we might get a version property in a bit.
+                    return self::UNKNOWN;
             }
         }
 
diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php
index 720ccf4..f441f8a 100644
--- a/lib/Parser/MimeDir.php
+++ b/lib/Parser/MimeDir.php
@@ -7,6 +7,7 @@ use Sabre\VObject\EofException;
 use Sabre\VObject\Component;
 use Sabre\VObject\Component\VCalendar;
 use Sabre\VObject\Component\VCard;
+use Sabre\VObject\Document;
 
 /**
  * MimeDir parser.
@@ -459,7 +460,7 @@ class MimeDir extends Parser {
             $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue());
         } else {
             $charset = $this->charset;
-            if (isset($propObj['CHARSET'])) {
+            if ($this->root->getDocumentType()===Document::VCARD21 && isset($propObj['CHARSET'])) {
                 // vCard 2.1 allows the character set to be specified per property.
                 $charset = (string)$propObj['CHARSET'];
             }
diff --git a/lib/Version.php b/lib/Version.php
index ccdffbe..97dfca1 100644
--- a/lib/Version.php
+++ b/lib/Version.php
@@ -14,6 +14,6 @@ class Version {
     /**
      * Full version number.
      */
-    const VERSION = '4.0.1';
+    const VERSION = '4.0.2';
 
 }
diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php
index a279f64..fcc4a46 100644
--- a/tests/VObject/Parser/MimeDirTest.php
+++ b/tests/VObject/Parser/MimeDirTest.php
@@ -49,6 +49,21 @@ VCF;
 
     }
 
+    function testIgnoreCharsetVCard30() {
+
+        $vcard = <<<VCF
+BEGIN:VCARD
+VERSION:3.0
+FN;CHARSET=unknown:foo-bar - \xFC
+END:VCARD\n
+VCF;
+
+        $mimeDir = new Mimedir();
+        $vcard = $mimeDir->parse($vcard);
+        $this->assertEquals("foo-bar - \xFC", $vcard->FN->getValue());
+
+    }
+
     function testDontDecodeLatin1() {
 
         $vcard = <<<VCF
@@ -85,7 +100,7 @@ VCF;
 
         $vcard = <<<VCF
 BEGIN:VCARD
-VERSION:3.0
+VERSION:2.1
 FN;CHARSET=foobar:nothing
 END:VCARD\n
 VCF;
@@ -115,7 +130,7 @@ VCF;
 
         $vcard = <<<VCF
 BEGIN:VCARD
-VERSION:3.0
+VERSION:2.1
 FN;CHARSET=Windows-1252:Euro \x80
 END:VCARD\n
 VCF;

-- 
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