[Pkg-owncloud-commits] [php-sabre-vobject] 08/19: Detect wrong ENCODING parameters.
David Prévot
taffit at moszumanska.debian.org
Tue May 19 20:10:13 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 7a37ebd21ecb0d71d9e9e13663fa41fdcd8bbadc
Author: Evert Pot <me at evertpot.com>
Date: Thu Mar 26 15:35:57 2015 -0700
Detect wrong ENCODING parameters.
Fixes #216.
---
ChangeLog.md | 3 +-
lib/Property.php | 77 +++++++++++++++++++++++++----------
tests/VObject/PropertyTest.php | 91 ++++++++++++++++++++++++++++++++----------
3 files changed, 129 insertions(+), 42 deletions(-)
diff --git a/ChangeLog.md b/ChangeLog.md
index 44bb1d9..5fb2312 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -4,7 +4,8 @@ ChangeLog
3.4.3 (2015-03-11)
------------------
-* #211: Fix BYDAY=-5TH in recurrence iterator. (@lindquist)
+* #211: Fix `BYDAY=-5TH` in recurrence iterator. (@lindquist)
+* #216: `ENCODING` parameter is now validated for all document types.
3.4.2 (2015-02-25)
diff --git a/lib/Property.php b/lib/Property.php
index 3e6704c..d9a8739 100644
--- a/lib/Property.php
+++ b/lib/Property.php
@@ -66,7 +66,7 @@ abstract class Property extends Node {
* @param string $group The vcard property group
* @return void
*/
- public function __construct(Component $root, $name, $value = null, array $parameters = array(), $group = null) {
+ function __construct(Component $root, $name, $value = null, array $parameters = array(), $group = null) {
$this->name = $name;
$this->group = $group;
@@ -91,7 +91,7 @@ abstract class Property extends Node {
* @param string|array $value
* @return void
*/
- public function setValue($value) {
+ function setValue($value) {
$this->value = $value;
@@ -108,7 +108,7 @@ abstract class Property extends Node {
*
* @return string
*/
- public function getValue() {
+ function getValue() {
if (is_array($this->value)) {
if (count($this->value)==0) {
@@ -130,7 +130,7 @@ abstract class Property extends Node {
* @param array $parts
* @return void
*/
- public function setParts(array $parts) {
+ function setParts(array $parts) {
$this->value = $parts;
@@ -144,7 +144,7 @@ abstract class Property extends Node {
*
* @return array
*/
- public function getParts() {
+ function getParts() {
if (is_null($this->value)) {
return array();
@@ -167,7 +167,7 @@ abstract class Property extends Node {
* @param string|null|array $value
* @return Node
*/
- public function add($name, $value = null) {
+ function add($name, $value = null) {
$noName = false;
if ($name === null) {
$name = Parameter::guessParameterNameByValue($value);
@@ -189,7 +189,7 @@ abstract class Property extends Node {
*
* @return array
*/
- public function parameters() {
+ function parameters() {
return $this->parameters;
@@ -203,7 +203,7 @@ abstract class Property extends Node {
*
* @return string
*/
- abstract public function getValueType();
+ abstract function getValueType();
/**
* Sets a raw value coming from a mimedir (iCalendar/vCard) file.
@@ -214,21 +214,21 @@ abstract class Property extends Node {
* @param string $val
* @return void
*/
- abstract public function setRawMimeDirValue($val);
+ abstract function setRawMimeDirValue($val);
/**
* Returns a raw mime-dir representation of the value.
*
* @return string
*/
- abstract public function getRawMimeDirValue();
+ abstract function getRawMimeDirValue();
/**
* Turns the object back into a serialized blob.
*
* @return string
*/
- public function serialize() {
+ function serialize() {
$str = $this->name;
if ($this->group) $str = $this->group . '.' . $this->name;
@@ -264,7 +264,7 @@ abstract class Property extends Node {
*
* @return array
*/
- public function getJsonValue() {
+ function getJsonValue() {
return $this->getParts();
@@ -278,7 +278,7 @@ abstract class Property extends Node {
* @param array $value
* @return void
*/
- public function setJsonValue(array $value) {
+ function setJsonValue(array $value) {
if (count($value)===1) {
$this->setValue(reset($value));
@@ -294,7 +294,7 @@ abstract class Property extends Node {
*
* @return array
*/
- public function jsonSerialize() {
+ function jsonSerialize() {
$parameters = array();
@@ -330,7 +330,7 @@ abstract class Property extends Node {
*
* @return string
*/
- public function __toString() {
+ function __toString() {
return (string)$this->getValue();
@@ -344,7 +344,7 @@ abstract class Property extends Node {
* @param mixed $name
* @return bool
*/
- public function offsetExists($name) {
+ function offsetExists($name) {
if (is_int($name)) return parent::offsetExists($name);
@@ -365,7 +365,7 @@ abstract class Property extends Node {
* @param string $name
* @return Node
*/
- public function offsetGet($name) {
+ function offsetGet($name) {
if (is_int($name)) return parent::offsetGet($name);
$name = strtoupper($name);
@@ -385,7 +385,7 @@ abstract class Property extends Node {
* @param mixed $value
* @return void
*/
- public function offsetSet($name, $value) {
+ function offsetSet($name, $value) {
if (is_int($name)) {
parent::offsetSet($name, $value);
@@ -407,7 +407,7 @@ abstract class Property extends Node {
* @param string $name
* @return void
*/
- public function offsetUnset($name) {
+ function offsetUnset($name) {
if (is_int($name)) {
parent::offsetUnset($name);
@@ -429,7 +429,7 @@ abstract class Property extends Node {
*
* @return void
*/
- public function __clone() {
+ function __clone() {
foreach($this->parameters as $key=>$child) {
$this->parameters[$key] = clone $child;
@@ -455,7 +455,7 @@ abstract class Property extends Node {
* @param int $options
* @return array
*/
- public function validate($options = 0) {
+ function validate($options = 0) {
$warnings = array();
@@ -506,6 +506,41 @@ abstract class Property extends Node {
}
+ if ($encoding = $this->offsetGet('ENCODING')) {
+
+ if ($this->root->getDocumentType()===Document::VCARD40) {
+ $warnings[] = array(
+ 'level' => 1,
+ 'message' => 'ENCODING parameter is not valid in vCard 4.',
+ 'node' => $this
+ );
+ } else {
+
+ $encoding = (string)$encoding;
+
+ switch($this->root->getDocumentType()) {
+ case Document::ICALENDAR20 :
+ $allowedEncoding = array('8BIT', 'BASE64');
+ break;
+ case Document::VCARD21 :
+ $allowedEncoding = array('QUOTED-PRINTABLE', 'BASE64', '8BIT');
+ break;
+ case Document::VCARD30 :
+ $allowedEncoding = array('B');
+ break;
+
+ }
+ if (!in_array(strtoupper($encoding), $allowedEncoding)) {
+ $warnings[] = array(
+ 'level' => 1,
+ 'message' => 'ENCODING=' . strtoupper($encoding) . ' is not valid for this document type.',
+ 'node' => $this
+ );
+ }
+ }
+
+ }
+
// Validating inner parameters
foreach($this->parameters as $param) {
$warnings = array_merge($warnings, $param->validate($options));
diff --git a/tests/VObject/PropertyTest.php b/tests/VObject/PropertyTest.php
index ec68edc..291d09b 100644
--- a/tests/VObject/PropertyTest.php
+++ b/tests/VObject/PropertyTest.php
@@ -3,11 +3,12 @@
namespace Sabre\VObject;
use
- Sabre\VObject\Component\VCalendar;
+ Sabre\VObject\Component\VCalendar,
+ Sabre\VObject\Component\VCard;
class PropertyTest extends \PHPUnit_Framework_TestCase {
- public function testToString() {
+ function testToString() {
$cal = new VCalendar();
@@ -19,7 +20,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testCreate() {
+ function testCreate() {
$cal = new VCalendar();
@@ -35,7 +36,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSetValue() {
+ function testSetValue() {
$cal = new VCalendar();
@@ -47,7 +48,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testParameterExists() {
+ function testParameterExists() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -59,7 +60,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testParameterGet() {
+ function testParameterGet() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -69,7 +70,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testParameterNotExists() {
+ function testParameterNotExists() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -79,7 +80,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testParameterMultiple() {
+ function testParameterMultiple() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -91,7 +92,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSetParameterAsString() {
+ function testSetParameterAsString() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -104,7 +105,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testUnsetParameter() {
+ function testUnsetParameter() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -115,7 +116,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSerialize() {
+ function testSerialize() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -124,7 +125,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSerializeParam() {
+ function testSerializeParam() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue', array(
@@ -136,7 +137,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSerializeNewLine() {
+ function testSerializeNewLine() {
$cal = new VCalendar();
$property = $cal->createProperty('SUMMARY',"line1\nline2");
@@ -145,7 +146,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSerializeLongLine() {
+ function testSerializeLongLine() {
$cal = new VCalendar();
$value = str_repeat('!',200);
@@ -157,7 +158,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testSerializeUTF8LineFold() {
+ function testSerializeUTF8LineFold() {
$cal = new VCalendar();
$value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a
@@ -167,7 +168,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testGetIterator() {
+ function testGetIterator() {
$cal = new VCalendar();
$it = new ElementList(array());
@@ -178,7 +179,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
- public function testGetIteratorDefault() {
+ function testGetIteratorDefault() {
$cal = new VCalendar();
$property = $cal->createProperty('propname','propvalue');
@@ -291,7 +292,6 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
-
function testValidateBadPropertyName() {
$calendar = new VCalendar();
@@ -332,7 +332,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
*
* @expectedException \LogicException
*/
- public function testArrayAccessSetInt() {
+ function testArrayAccessSetInt() {
$calendar = new VCalendar();
$property = $calendar->createProperty("X-PROP", null);
@@ -347,7 +347,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
*
* @expectedException \LogicException
*/
- public function testArrayAccessUnsetInt() {
+ function testArrayAccessUnsetInt() {
$calendar = new VCalendar();
$property = $calendar->createProperty("X-PROP", null);
@@ -357,4 +357,55 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
}
+ function testValidateBadEncoding() {
+
+ $document = new VCalendar();
+ $property = $document->add('X-FOO','value');
+ $property['ENCODING'] = 'invalid';
+
+ $result = $property->validate();
+
+ $this->assertEquals('ENCODING=INVALID is not valid for this document type.', $result[0]['message']);
+ $this->assertEquals(1, $result[0]['level']);
+
+ }
+
+ function testValidateBadEncodingVCard4() {
+
+ $document = new VCard(['VERSION' => '4.0']);
+ $property = $document->add('X-FOO','value');
+ $property['ENCODING'] = 'BASE64';
+
+ $result = $property->validate();
+
+ $this->assertEquals('ENCODING parameter is not valid in vCard 4.', $result[0]['message']);
+ $this->assertEquals(1, $result[0]['level']);
+
+ }
+
+ function testValidateBadEncodingVCard3() {
+
+ $document = new VCard(['VERSION' => '3.0']);
+ $property = $document->add('X-FOO','value');
+ $property['ENCODING'] = 'BASE64';
+
+ $result = $property->validate();
+
+ $this->assertEquals('ENCODING=BASE64 is not valid for this document type.', $result[0]['message']);
+ $this->assertEquals(1, $result[0]['level']);
+
+ }
+
+ function testValidateBadEncodingVCard21() {
+
+ $document = new VCard(['VERSION' => '2.1']);
+ $property = $document->add('X-FOO','value');
+ $property['ENCODING'] = 'B';
+
+ $result = $property->validate();
+
+ $this->assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']);
+ $this->assertEquals(1, $result[0]['level']);
+
+ }
}
--
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