[Pkg-owncloud-commits] [php-sabre-vobject] 26/43: Skip the BOM if exists.

David Prévot taffit at moszumanska.debian.org
Sat Jan 10 14:20:16 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 5679ac5abe8c4cb5bd2dfb627c192f8d8a117a84
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Wed Jan 7 10:29:51 2015 +0100

    Skip the BOM if exists.
---
 lib/Parser/MimeDir.php       | 10 ++++++++++
 tests/VObject/ReaderTest.php | 11 +++++++++++
 2 files changed, 21 insertions(+)

diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php
index e90832f..1b87374 100644
--- a/lib/Parser/MimeDir.php
+++ b/lib/Parser/MimeDir.php
@@ -100,6 +100,16 @@ class MimeDir extends Parser {
     protected function parseDocument() {
 
         $line = $this->readLine();
+
+        // BOM is ZERO WIDTH NO-BREAK SPACE (U+FEFF).
+        // It's 0xEF 0xBB 0xBF in UTF-8 hex.
+        if (   3 <= strlen($line)
+            && ord($line[0]) === 0xef
+            && ord($line[1]) === 0xbb
+            && ord($line[2]) === 0xbf) {
+            $line = substr($line, 3);
+        }
+
         switch(strtoupper($line)) {
             case 'BEGIN:VCALENDAR' :
                 $class = isset(VCalendar::$componentMap['VCALENDAR'])
diff --git a/tests/VObject/ReaderTest.php b/tests/VObject/ReaderTest.php
index 9140e5a..2801ee7 100644
--- a/tests/VObject/ReaderTest.php
+++ b/tests/VObject/ReaderTest.php
@@ -435,4 +435,15 @@ ICS;
 
     }
 
+    public function testReadBOM() {
+
+        $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
+        $result = Reader::read($data);
+
+        $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
+        $this->assertEquals('VCALENDAR', $result->name);
+        $this->assertEquals(0, count($result->children));
+
+    }
+
 }

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