Skip to content

Commit

Permalink
throw an exception instead of an error when fails to decode mime
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikbosch committed Oct 11, 2017
1 parent cbbea89 commit 8bbcb39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public static function fromString(string $addressAsString)
$name = substr($name, 1, -1);
}

return new self(new EmailAddress($email), iconv_mime_decode($name));
$name = @iconv_mime_decode($name);
if ($name === false) {
throw new \InvalidArgumentException('Failed to mime decode the name');
}

return new self(new EmailAddress($email), $name);
}
}
12 changes: 12 additions & 0 deletions test/Unit/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ public function it_is_equal_when_it_has_same_value()
);
}

/**
* @test
*/
public function it_fails_when_it_contains_bad_characters()
{
$this->expectException(\InvalidArgumentException::class);

Address::fromString(
(string)(new Address(new EmailAddress('[email protected]'), 'MariÃ?«lla Test'))
);
}

/**
* @test
* @dataProvider provideAddressStrings
Expand Down

0 comments on commit 8bbcb39

Please sign in to comment.