Skip to content

Commit

Permalink
Fix \mb_convert_encoding error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
morzechowskiproget authored and mateuszorzechowski committed Sep 29, 2022
1 parent 2b8b619 commit 17c8532
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/VCardParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected function parse()
} elseif (strpos(strtolower($type), 'charset=') === 0) {
try {
$value = mb_convert_encoding($value, "UTF-8", substr($type, 8));
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
unset($types[$i]);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/VCardParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,14 @@ public function testLabel()
$parser = new VCardParser($vcard->buildVCard());
$this->assertEquals($parser->getCardAtIndex(0)->label, $label);
}

public function testInvalidEndingConversion()
{
$parser = VCardParser::parseFromFile(__DIR__ . '/invalid_encoding.vcf');

$cards = $parser->getCards();

$this->assertEquals($cards[0]->firstname, 'Jeroen');
$this->assertEquals($cards[0]->lastname, 'Desloovere');
}
}
10 changes: 10 additions & 0 deletions tests/invalid_encoding.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN:VCARD
VERSION:3.0
REV:2016-05-30T10:36:13Z
N;CHARSET=invalid-encoding:Desloovere;Jeroen;;;
FN;CHARSET=utf-8:Jeroen Desloovere
item1.EMAIL;type=INTERNET:[email protected]
item1.X-ABLabel:$!<Email>!$
item2.URL:http://www.jeroendesloovere.be
item2.X-ABLabel:$!<Home>!$
END:VCARD

0 comments on commit 17c8532

Please sign in to comment.