Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/141'
Browse files Browse the repository at this point in the history
Close #141
  • Loading branch information
weierophinney committed Jun 8, 2017
2 parents 536377c + eb5e441 commit 427981f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ All notable changes to this project will be documented in this file, in reverse
While malformed addresses should never reach this class, this extra hardening
helps ensure safety in cases where a developer codes their own
`AddressInterface` implementations for these types of addresses.
- [#141](https://github.com/zendframework/zend-mail/pull/141) updates
`Zend\Mail\Message::getHeaders()` to throw an exception in a case where the
`$headers` property is not a `Headers` instance.

### Deprecated

Expand Down
6 changes: 6 additions & 0 deletions src/Storage/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public function countParts()
* Lazy-loads if not already attached.
*
* @return Headers
* @throws Exception\RuntimeException
*/
public function getHeaders()
{
Expand All @@ -277,6 +278,11 @@ public function getHeaders()
$this->headers = new Headers();
}
}
if (! $this->headers instanceof Headers) {
throw new Exception\RuntimeException(
'$this->headers must be an instance of Headers'
);
}

return $this->headers;
}
Expand Down
12 changes: 12 additions & 0 deletions test/Storage/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ public function testEmptyHeader()
$this->setExpectedException('Zend\\Mail\\Exception\\InvalidArgumentException');
$message->subject;
}

public function testWrongHeaderType()
{
// @codingStandardsIgnoreStart
$badMessage = unserialize(
"O:25:\"Zend\Mail\Storage\Message\":9:{s:8:\"\x00*\x00flags\";a:0:{}s:10:\"\x00*\x00headers\";s:16:\"Yellow submarine\";s:10:\"\x00*\x00content\";N;s:11:\"\x00*\x00topLines\";s:0:\"\";s:8:\"\x00*\x00parts\";a:0:{}s:13:\"\x00*\x00countParts\";N;s:15:\"\x00*\x00iterationPos\";i:1;s:7:\"\x00*\x00mail\";N;s:13:\"\x00*\x00messageNum\";i:0;}"
);
// @codingStandardsIgnoreEnd

$this->setExpectedException(MailException\RuntimeException::class);
$badMessage->getHeaders();
}

public function testEmptyBody()
{
Expand Down

0 comments on commit 427981f

Please sign in to comment.