[Pkg-owncloud-commits] [php-sabre-vobject] 11/19: More validator output.
David Prévot
taffit at moszumanska.debian.org
Sun Jun 15 02:08:54 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 3b54276d8331045195b2a187c96eae17565845b6
Author: Evert Pot <me at evertpot.com>
Date: Thu Jun 5 12:30:25 2014 -0400
More validator output.
---
ChangeLog.md | 3 ++-
lib/Sabre/VObject/Cli.php | 25 ++++++++++++++++++++++---
lib/Sabre/VObject/Property.php | 24 +++++++++++++++++++-----
tests/Sabre/VObject/PropertyTest.php | 2 +-
4 files changed, 44 insertions(+), 10 deletions(-)
diff --git a/ChangeLog.md b/ChangeLog.md
index e7be14d..317ad39 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -7,7 +7,8 @@ ChangeLog
* Validator now checks if DUE and DTSTART are of the same type in VTODO, and
ensures that DUE is always after DTSTART.
* Removed documentation from source repository, to http://sabre.io/vobject/
-
+* Expanded the vobject cli tool validation output to make it easier to find
+ issues.
3.2.2 (2014-05-07)
diff --git a/lib/Sabre/VObject/Cli.php b/lib/Sabre/VObject/Cli.php
index fd459b0..f15636c 100644
--- a/lib/Sabre/VObject/Cli.php
+++ b/lib/Sabre/VObject/Cli.php
@@ -345,10 +345,19 @@ HELP
$this->log(" No warnings!");
} else {
+ $levels = [
+ 1 => 'REPAIRED',
+ 2 => 'WARNING',
+ 3 => 'ERROR',
+ ];
$returnCode = 2;
foreach($warnings as $warn) {
- $this->log(" " . $warn['message']);
+ $extra = '';
+ if ($warn['node'] instanceof Property) {
+ $extra = ' (property: "' . $warn['node']->name . '")';
+ }
+ $this->log(" [" . $levels[$warn['level']] . '] ' . $warn['message'] . $extra);
}
@@ -381,10 +390,20 @@ HELP
if (!count($warnings)) {
$this->log(" No warnings!");
} else {
+
+ $levels = [
+ 1 => 'REPAIRED',
+ 2 => 'WARNING',
+ 3 => 'ERROR',
+ ];
+ $returnCode = 2;
foreach($warnings as $warn) {
- $returnCode = 2;
- $this->log(" " . $warn['message']);
+ $extra = '';
+ if ($warn['node'] instanceof Property) {
+ $extra = ' (property: "' . $warn['node']->name . '")';
+ }
+ $this->log(" [" . $levels[$warn['level']] . '] ' . $warn['message'] . $extra);
}
diff --git a/lib/Sabre/VObject/Property.php b/lib/Sabre/VObject/Property.php
index 7582ddc..f85825b 100644
--- a/lib/Sabre/VObject/Property.php
+++ b/lib/Sabre/VObject/Property.php
@@ -461,14 +461,28 @@ abstract class Property extends Node {
// Checking if our value is UTF-8
if (!StringUtil::isUTF8($this->getRawMimeDirValue())) {
+
+ $oldValue = $this->getRawMimeDirValue();
+ $level = 3;
+ if ($options & self::REPAIR) {
+ $newValue = StringUtil::convertToUTF8($oldValue);
+ if (StringUtil::isUTF8($newValue)) {
+ $this->setRawMimeDirValue($newValue);
+ $level = 1;
+ }
+
+ }
+
+ $message = 'Property is not valid UTF-8!';
+ if (preg_match('%([\x00-\x08\x0B-\x0C\x0E\x0F])%', $oldValue, $matches)) {
+ $message = 'Property contained a control character (0x' . bin2hex($matches[1]) . ')';
+ }
+
$warnings[] = array(
- 'level' => 1,
- 'message' => 'Property is not valid UTF-8!',
+ 'level' => $level,
+ 'message' => $message,
'node' => $this,
);
- if ($options & self::REPAIR) {
- $this->setRawMimeDirValue(StringUtil::convertToUTF8($this->getRawMimeDirValue()));
- }
}
// Checking if the propertyname does not contain any invalid bytes.
diff --git a/tests/Sabre/VObject/PropertyTest.php b/tests/Sabre/VObject/PropertyTest.php
index d220567..fe520ff 100644
--- a/tests/Sabre/VObject/PropertyTest.php
+++ b/tests/Sabre/VObject/PropertyTest.php
@@ -263,7 +263,7 @@ class PropertyTest extends \PHPUnit_Framework_TestCase {
$property = $calendar->createProperty('X-PROP', "Bla\x00");
$result = $property->validate(Property::REPAIR);
- $this->assertEquals('Property is not valid UTF-8!', $result[0]['message']);
+ $this->assertEquals('Property contained a control character (0x00)', $result[0]['message']);
$this->assertEquals('Bla', $property->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