Merge pull request #9108 from cakephp/issue-9106

Don't split strings headers that lack a ':'.
This commit is contained in:
Mark Story 2016-07-15 22:20:13 -04:00 committed by GitHub
commit 876b508797
2 changed files with 6 additions and 2 deletions

View file

@ -577,7 +577,7 @@ class CakeResponse {
if (is_numeric($header)) { if (is_numeric($header)) {
list($header, $value) = array($value, null); list($header, $value) = array($value, null);
} }
if ($value === null) { if ($value === null && strpos($header, ':') !== false) {
list($header, $value) = explode(':', $header, 2); list($header, $value) = explode(':', $header, 2);
} }
$this->_headers[$header] = is_array($value) ? array_map('trim', $value) : trim($value); $this->_headers[$header] = is_array($value) ? array_map('trim', $value) : trim($value);

View file

@ -164,11 +164,15 @@ class CakeResponseTest extends CakeTestCase {
$headers += array('Location' => 'http://example.com'); $headers += array('Location' => 'http://example.com');
$this->assertEquals($headers, $response->header()); $this->assertEquals($headers, $response->header());
//Headers with the same name are overwritten // Headers with the same name are overwritten
$response->header('Location', 'http://example2.com'); $response->header('Location', 'http://example2.com');
$headers = array('Location' => 'http://example2.com'); $headers = array('Location' => 'http://example2.com');
$this->assertEquals($headers, $response->header()); $this->assertEquals($headers, $response->header());
$response->header('Date', null);
$headers += array('Date' => null);
$this->assertEquals($headers, $response->header());
$response->header(array('WWW-Authenticate' => 'Negotiate')); $response->header(array('WWW-Authenticate' => 'Negotiate'));
$headers += array('WWW-Authenticate' => 'Negotiate'); $headers += array('WWW-Authenticate' => 'Negotiate');
$this->assertEquals($headers, $response->header()); $this->assertEquals($headers, $response->header());