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

Skip to content

Commit 2345ec1

Browse files
committed
bug #19549 [HttpFoundation] fixed Request::getContent() reusage bug (1ma)
This PR was squashed before being merged into the 2.7 branch (closes #19549). Discussion ---------- [HttpFoundation] fixed Request::getContent() reusage bug | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | After calling ```Request::getContent(true)```, subsequent calls to the same instance method (withouth the ```$asResource``` flag) always returned ```false``` instead of the request body as a plain string. A unit test already existed to guard against this behaviour (the 'Resource then fetch' case) but it yielded a false positive because it was comparing ```''``` to ```false``` using PHPUnit's ```assertEquals``` method instead of ```assertSame```. For completeness sake I also added the missing usage permutations in the data provider, which already worked OK. Commits ------- c42ac66 [HttpFoundation] fixed Request::getContent() reusage bug
2 parents 1a059e5 + c42ac66 commit 2345ec1

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