diff --git a/lib/Property.php b/lib/Property.php index 4aa26d517..41ecbc3df 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['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()