8000 [HttpFoundation] fixed Request::getContent() reusage bug · symfony/symfony@c42ac66 · GitHub
[go: up one dir, main page]

Skip to content

Commit c42ac66

Browse files
1mafabpot
authored andcommitted
[HttpFoundation] fixed Request::getContent() reusage bug
1 parent aae8e3d commit c42ac66

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ public function getContent($asResource = false)
15161516
return stream_get_contents($this->content);
15171517
}
15181518

1519-
if (null === $this->content) {
1519+
if (null === $this->content || false === $this->content) {
15201520
$this->content = file_get_contents('php://input');
15211521
}
15221522

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,16 @@ public function testGetContentCantBeCalledTwiceWithResources($first, $second)
10421042
$req->getContent($second);
10431043
}
10441044

1045+
public function getContentCantBeCalledTwiceWithResourcesProvider()
1046+
{
1047+
return array(
1048+
'Resource then fetch' => array(true, false),
1049+
'Resource then resource' => array(true, true),
1050+
);
1051+
}
1052+
10451053
/**
1046-
* @dataProvider getContentCantBeCalledTwiceWithResourcesProvider
1054+
* @dataProvider getContentCanBeCalledTwiceWithResourcesProvider
10471055
* @requires PHP 5.6
10481056
*/
10491057
public function testGetContentCanBeCalledTwiceWithResources($first, $second)
@@ -1060,12 +1068,14 @@ public function testGetContentCanBeCalledTwiceWithResources($first, $second)
10601068
$b = stream_get_contents($b);
10611069
}
10621070

1063-
$this->assertEquals($a, $b);
1071+
$this->assertSame($a, $b);
10641072
}
10651073

1066-
public function getContentCantBeCalledTwiceWithResourcesProvider()
1074+
public function getContentCanBeCalledTwiceWithResourcesProvider()
10671075
{
10681076
return array(
1077+
'Fetch then fetch' => array(false, false),
1078+
'Fetch then resource' => array(false, true),
10691079
'Resource then fetch' => array(true, false),
10701080
'Resource then resource' => array(true, true),
10711081
);

0 commit comments

Comments
 (0)
0