Skip to content

Commit

Permalink
Repairing BASE64 encoded vCard version 3 (#441)
Browse files Browse the repository at this point in the history
* Repairing BASE64 encoded vCard version 3

* Apply suggestions from code review

Co-Authored-By: Webbeh <info@geeq.ch>
  • Loading branch information
Webbeh authored and evert committed Dec 26, 2018
1 parent 5b86533 commit e064da1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Property.php
Expand Up @@ -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)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/VObject/PropertyTest.php
Expand Up @@ -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()
Expand Down

0 comments on commit e064da1

Please sign in to comment.