Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repairing BASE64 encoded vCard version 3 #441

Merged
merged 2 commits into from Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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