[Pkg-owncloud-commits] [php-sabre-vobject] 02/128: Decoding badly encoded URL's from Google.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 23:10:57 UTC 2014
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 3a895f803ec041e34559611664d3f5156b400673
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Sat Oct 19 13:41:34 2013 -0400
Decoding badly encoded URL's from Google.
---
lib/Sabre/VObject/Property/Uri.php | 30 +++++++++++++++++++++++-
tests/Sabre/VObject/GoogleColonEscapingTest.php | 31 +++++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/lib/Sabre/VObject/Property/Uri.php b/lib/Sabre/VObject/Property/Uri.php
index 5c14717..c5a0e4b 100644
--- a/lib/Sabre/VObject/Property/Uri.php
+++ b/lib/Sabre/VObject/Property/Uri.php
@@ -48,7 +48,35 @@ class Uri extends Property {
*/
public function setRawMimeDirValue($val) {
- $this->value = $val;
+ // Normally we don't need to do any type of unescaping for these
+ // properties, however.. we've noticed that Google Contacts
+ // specifically escapes the colon (:) with a blackslash. While I have
+ // no clue why they thought that was a good idea, I'm unescaping it
+ // anyway.
+ //
+ // Good thing backslashes are not allowed in urls. Makes it easy to
+ // assume that a backslash is always intended as an escape character.
+ if ($this->name === 'URL') {
+ $regex = '# (?: (\\\\ (?: \\\\ | : ) ) ) #x';
+ $matches = preg_split($regex, $val, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
+ $newVal = '';
+ foreach($matches as $match) {
+ switch($match) {
+ case '\\\\' :
+ $newVal.='\\';
+ break;
+ case '\:' :
+ $newVal.=':';
+ break;
+ default :
+ $newVal.=$match;
+ break;
+ }
+ }
+ $this->value = $newVal;
+ } else {
+ $this->value = $val;
+ }
}
diff --git a/tests/Sabre/VObject/GoogleColonEscapingTest.php b/tests/Sabre/VObject/GoogleColonEscapingTest.php
new file mode 100644
index 0000000..0961ec1
--- /dev/null
+++ b/tests/Sabre/VObject/GoogleColonEscapingTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Sabre\VObject;
+
+/**
+ * Google produces vcards with a weird escaping of urls.
+ *
+ * VObject will provide a workaround for this, so end-user still get expected
+ * values.
+ */
+class GoogleColonEscaping extends \PHPUnit_Framework_TestCase {
+
+ function testDecode() {
+
+ $vcard = <<<VCF
+BEGIN:VCARD
+VERSION:3.0
+FN:Evert Pot
+N:Pot;Evert;;;
+EMAIL;TYPE=INTERNET;TYPE=WORK:evert at fruux.com
+BDAY:1985-04-07
+item7.URL:http\://www.rooftopsolutions.nl/
+END:VCARD
+VCF;
+
+ $vobj = Reader::read($vcard);
+ $this->assertEquals('http://www.rooftopsolutions.nl/', $vobj->URL->getValue());
+
+ }
+
+}
--
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