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/zendframework/zendframework#6657-unfolding-of-mu…
Browse files Browse the repository at this point in the history
…lti-line-headershould-not-strip-whitespace' into develop

Close zendframework/zendframework#6657
  • Loading branch information
Ocramius committed Dec 30, 2014
3 parents a53bcb4 + 6abd55e + a8b5fcf commit 78fe6d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ public static function fromString($string, $EOL = self::EOL)
// iterate the header lines, some might be continuations
foreach (explode($EOL, $string) as $line) {
// check if a header name is present
if (preg_match('/^(?P<name>[\x21-\x39\x3B-\x7E]+):.*$/', $line, $matches)) {
if (preg_match('/^[\x21-\x39\x3B-\x7E]+:.*$/', $line)) {
if ($currentLine) {
// a header name was present, then store the current complete line
$headers->addHeaderLine($currentLine);
}
$currentLine = trim($line);
} elseif (preg_match('/^\s+.*$/', $line, $matches)) {
} elseif (preg_match('/^\s+.*$/', $line)) {
// continuation: append to current line
$currentLine .= trim($line);
// recover the whitespace that break the line (unfolding, rfc2822#section-2.2.3)
$currentLine .= ' ' . trim($line);
} elseif (preg_match('/^\s*$/', $line)) {
// empty line indicates end of headers
break;
Expand Down
5 changes: 4 additions & 1 deletion test/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function testHeadersFromStringFactoryHandlesMissingWhitespace()
$this->assertEquals('foo-bar', $header->getFieldValue());
}

/**
* @group 6657
*/
public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationLine()
{
$headers = Mail\Headers::fromString("Fake: foo-bar,\r\n blah-blah");
Expand All @@ -54,7 +57,7 @@ public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationL
$header = $headers->get('fake');
$this->assertInstanceOf('Zend\Mail\Header\GenericHeader', $header);
$this->assertEquals('Fake', $header->getFieldName());
$this->assertEquals('foo-bar,blah-blah', $header->getFieldValue());
$this->assertEquals('foo-bar, blah-blah', $header->getFieldValue());
}

public function testHeadersFromStringFactoryCreatesSingleObjectWithHeaderBreakLine()
Expand Down

0 comments on commit 78fe6d0

Please sign in to comment.