From 7bf4ab9753e92695b1e492a85da6a8125d523b74 Mon Sep 17 00:00:00 2001 From: Weby Date: Mon, 24 Dec 2018 12:07:37 +0100 Subject: [PATCH 1/2] Repairing BASE64 encoded vCard version 3 --- lib/Property.php | 12 ++++++++++++ tests/VObject/PropertyTest.php | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Property.php b/lib/Property.php index 4aa26d517..76327347f 100644 --- a/lib/Property.php +++ b/lib/Property.php @@ -572,6 +572,18 @@ public function validate($options = 0) break; case Document::VCARD30: $allowedEncoding = ['B']; + //Repair vCard30 that use BASE64 encoding + if ($options & self::REPAIR) { + if ('BASE64' == strtoupper($encoding)) { + $encoding = 'B'; + $this->offsetSet('ENCODING', $encoding); + $warnings[] = [ + 'level' => 1, + 'message' => 'ENCODING=BASE64 has been transformed to ENCODING=B.', + 'node' => $this, + ]; + } + } break; } if ($allowedEncoding && !in_array(strtoupper($encoding), $allowedEncoding)) { diff --git a/tests/VObject/PropertyTest.php b/tests/VObject/PropertyTest.php index 0bc8afc90..1c2dc0830 100644 --- a/tests/VObject/PropertyTest.php +++ b/tests/VObject/PropertyTest.php @@ -368,6 +368,12 @@ public function testValidateBadEncodingVCard3() $this->assertEquals('ENCODING=BASE64 is not valid for this document type.', $result[0]['message']); $this->assertEquals(3, $result[0]['level']); + + //Validate the reparation of BASE64 formatted vCard v3 + $result = $property->validate(Property::REPAIR); + + $this->assertEquals('ENCODING=BASE64 has been transformed to ENCODING=B.', $result[0]['message']); + $this->assertEquals(1, $result[0]['level']); } public function testValidateBadEncodingVCard21() From 24bb625178aa23b783767f0ad07d323580373538 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Tue, 25 Dec 2018 07:37:10 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-Authored-By: Webbeh --- lib/Property.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Property.php b/lib/Property.php index 76327347f..41ecbc3df 100644 --- a/lib/Property.php +++ b/lib/Property.php @@ -574,9 +574,9 @@ public function validate($options = 0) $allowedEncoding = ['B']; //Repair vCard30 that use BASE64 encoding if ($options & self::REPAIR) { - if ('BASE64' == strtoupper($encoding)) { + if ('BASE64' === strtoupper($encoding)) { $encoding = 'B'; - $this->offsetSet('ENCODING', $encoding); + $this['ENCODING'] = $encoding; $warnings[] = [ 'level' => 1, 'message' => 'ENCODING=BASE64 has been transformed to ENCODING=B.',