[Pkg-owncloud-commits] [php-sabre-vobject] 36/46: Support Windows-1252 when decoding.
David Prévot
taffit at moszumanska.debian.org
Thu Dec 10 02:12:41 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 9f080f3cd64db791dcebe21275d6bf13857cf3d9
Author: Evert Pot <me at evertpot.com>
Date: Fri Nov 27 17:46:08 2015 -0500
Support Windows-1252 when decoding.
Fixes #41
---
CHANGELOG.md | 1 +
lib/Parser/MimeDir.php | 18 ++++++++++++++----
tests/VObject/Parser/MimeDirTest.php | 31 +++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f983d35..e6b92b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ ChangeLog
* #220: Automatically stop recurring after 3500 recurrences.
* #41: Allow user to set different encoding than UTF-8 when decoding vCards.
* #41: Support the `ENCODING` parameter from vCard 2.1.
+ Both ISO-8859-1 and Windows-1252 are currently supported.
* #185: Fix encoding/decoding of `TIME` values in jCal/jCard.
diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php
index 7a6e28c..3a0f06c 100644
--- a/lib/Parser/MimeDir.php
+++ b/lib/Parser/MimeDir.php
@@ -52,6 +52,15 @@ class MimeDir extends Parser {
protected $charset = 'UTF-8';
/**
+ * The list of character sets we support when decoding.
+ */
+ const SUPPORTED_CHARSETS = [
+ 'UTF-8',
+ 'ISO-8859-1',
+ 'Windows-1252',
+ ];
+
+ /**
* Parses an iCalendar or vCard file.
*
* Pass a stream or a string. If null is parsed, the existing buffer is
@@ -94,10 +103,8 @@ class MimeDir extends Parser {
*/
function setCharset($charset) {
- $supportedEncodings = ['UTF-8', 'ISO-8859-1'];
-
- if (!in_array($charset, $supportedEncodings)) {
- throw new \InvalidArgumentException('Unsupported encoding. (Supported encodings: ' . implode(', ', $supportedEncodings) . ')');
+ if (!in_array($charset, self::SUPPORTED_CHARSETS)) {
+ throw new \InvalidArgumentException('Unsupported encoding. (Supported encodings: ' . implode(', ', self::SUPPORTED_CHARSETS) . ')');
}
$this->charset = $charset;
@@ -460,6 +467,9 @@ class MimeDir extends Parser {
case 'ISO-8859-1' :
$property['value'] = utf8_encode($property['value']);
break;
+ case 'Windows-1252' :
+ $property['value'] = mb_convert_encoding($property['value'], 'UTF-8', $charset);
+ break;
default :
throw new ParseException('Unsupported CHARSET: ' . $propObj['CHARSET']);
}
diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php
index 7ce66b8..a279f64 100644
--- a/tests/VObject/Parser/MimeDirTest.php
+++ b/tests/VObject/Parser/MimeDirTest.php
@@ -94,4 +94,35 @@ VCF;
$mimeDir->parse($vcard);
}
+
+ function testDecodeWindows1252() {
+
+ $vcard = <<<VCF
+BEGIN:VCARD
+VERSION:3.0
+FN:Euro \x80
+END:VCARD\n
+VCF;
+
+ $mimeDir = new Mimedir();
+ $mimeDir->setCharSet('Windows-1252');
+ $vcard = $mimeDir->parse($vcard);
+ $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue());
+
+ }
+
+ function testDecodeWindows1252Inline() {
+
+ $vcard = <<<VCF
+BEGIN:VCARD
+VERSION:3.0
+FN;CHARSET=Windows-1252:Euro \x80
+END:VCARD\n
+VCF;
+
+ $mimeDir = new Mimedir();
+ $vcard = $mimeDir->parse($vcard);
+ $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->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