Skip to content

Commit

Permalink
Fixes #17180: Do not populate yii\web\Response::$response when resp…
Browse files Browse the repository at this point in the history
…onse code is 204
  • Loading branch information
mikk150 authored and samdark committed Mar 5, 2019
1 parent bf89d95 commit 81f7d38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Yii Framework 2 Change Log

- Bug #17156: Fixes PHP 7.2 warning when a data provider has no data as a parameter for a GridView (evilito)
- Bug #17083: Fixed `yii\validators\EmailValidator::$checkDNS` tells that every domain is correct on alpine linux (mikk150)
- Bug #17180: Do not populate `yii\web\Response::$response` when response code is 204 (mikk150)


2.0.16.1 February 28, 2019
Expand Down
10 changes: 6 additions & 4 deletions framework/web/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,6 @@ protected function sendCookies()
*/
protected function sendContent()
{
if ($this->getStatusCode() === 204) {
return;
}

if ($this->stream === null) {
echo $this->content;

Expand Down Expand Up @@ -1035,6 +1031,12 @@ protected function defaultFormatters()
*/
protected function prepare()
{
if ($this->statusCode === 204) {
$this->content = '';
$this->stream = null;
return;
}

if ($this->stream !== null) {
return;
}
Expand Down
28 changes: 28 additions & 0 deletions tests/framework/web/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,32 @@ public function testEmptyContentOn204()
$content = ob_get_clean();
$this->assertSame($content, '');
}

public function testSettingContentToNullOn204()
{
$response = new Response();
$response->setStatusCode(204);
$response->content = 'not empty content';

ob_start();
$response->send();
$content = ob_get_clean();
$this->assertSame($content, '');
$this->assertSame($response->content, '');
}

public function testSettingStreamToNullOn204()
{
$response = new Response();
$dataFile = \Yii::getAlias('@yiiunit/data/web/data.txt');

$response->sendFile($dataFile);
$response->setStatusCode(204);

ob_start();
$response->send();
$content = ob_get_clean();
$this->assertSame($content, '');
$this->assertNull($response->stream);
}
}

0 comments on commit 81f7d38

Please sign in to comment.