Skip to content

Commit c9da1ae

Browse files
Merge branch '2.3' into 2.6
* 2.3: [Form] NativeRequestHandler file handling fix [HttpKernel] Throw double-bounce exceptions minor #13377 [Console] Change greater by greater or equal for isFresh in FileResource [2.3] [HttpFoundation] fixed param order for Nginx's x-accel-redirect
2 parents 70ba475 + e0ba4d6 commit c9da1ae

File tree

13 files changed

+77
-27
lines changed

13 files changed

+77
-27
lines changed

src/Symfony/Component/Config/Resource/FileResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function isFresh($timestamp)
6060
return false;
6161
}
6262

63-
return filemtime($this->resource) < $timestamp;
63+
return filemtime($this->resource) <= $timestamp;
6464
}
6565

6666
public function serialize()

src/Symfony/Component/Config/Tests/ConfigCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function makeCacheFresh()
128128

129129
private function makeCacheStale()
130130
{
131-
touch($this->cacheFile, time() - 3600);
131+
touch($this->cacheFile, filemtime($this->resourceFile) - 3600);
132132
}
133133

134134
private function generateMetaFile()

src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ class FileResourceTest extends \PHPUnit_Framework_TestCase
1717
{
1818
protected $resource;
1919
protected $file;
20+
protected $time;
2021

2122
protected function setUp()
2223
{
2324
$this->file = realpath(sys_get_temp_dir()).'/tmp.xml';
24-
touch($this->file);
25+
$this->time = time();
26+
touch($this->file, $this->time);
2527
$this->resource = new FileResource($this->file);
2628
}
2729

@@ -42,11 +44,12 @@ public function testToString()
4244

4345
public function testIsFresh()
4446
{
45-
$this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
46-
$this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
47+
$this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
48+
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
49+
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
4750

4851
$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
49-
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
52+
$this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
5053
}
5154

5255
public function testSerializeUnserialize()

src/Symfony/Component/Form/NativeRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function handleRequest(FormInterface $form, $request = null)
9898
}
9999

100100
$fixedFiles = array();
101-
foreach ($_FILES as $name => $file) {
102-
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
101+
foreach ($_FILES as $fileKey => $file) {
102+
$fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
103103
}
104104

105105
if ('' === $name) {

src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,50 @@ public function testSubmitFileIfNoParam($method)
266266
$this->requestHandler->handleRequest($form, $this->request);
267267
}
268268

269+
/**
270+
* @dataProvider methodExceptGetProvider
271+
*/
272+
public function testSubmitMultipleFiles($method)
273+
{
274+
$form = $this->getMockForm('param1', $method);
275+
$file = $this->getMockFile();
276+
277+
$this->setRequestData($method, array(
278+
'param1' => null,
279+
), array(
280+
'param2' => $this->getMockFile('2'),
281+
'param1' => $file,
282+
'param3' => $this->getMockFile('3'),
283+
));
284+
285+
$form->expects($this->once())
286+
->method('submit')
287+
->with($file, 'PATCH' !== $method);
288+
289+
$this->requestHandler->handleRequest($form, $this->request);
290+
}
291+
292+
/**
293+
* @dataProvider methodExceptGetProvider
294+
*/
295+
public function testSubmitFileWithNamelessForm($method)
296+
{
297+
$form = $this->getMockForm(null, $method);
298+
$file = $this->getMockFile();
299+
300+
$this->setRequestData($method, array(
301+
'' => null,
302+
), array(
303+
'' => $file,
304+
));
305+
306+
$form->expects($this->once())
307+
->method('submit')
308+
->with($file, 'PATCH' !== $method);
309+
310+
$this->requestHandler->handleRequest($form, $this->request);
311+
}
312+
269313
/**
270314
* @dataProvider getPostMaxSizeFixtures
271315
*/
@@ -314,7 +358,7 @@ abstract protected function setRequestData($method, $data, $files = array());
314358

315359
abstract protected function getRequestHandler();
316360

317-
abstract protected function getMockFile();
361+
abstract protected function getMockFile($suffix = '');
318362

319363
protected function getMockForm($name, $method = null, $compound = true)
320364
{

src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ protected function getRequestHandler()
4646
return new HttpFoundationRequestHandler($this->serverParams);
4747
}
4848

49-
protected function getMockFile()
49+
protected function getMockFile($suffix = '')
5050
{
51-
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
51+
return new UploadedFile(__DIR__.'/../../Fixtures/foo'.$suffix, 'foo'.$suffix);
5252
}
5353
}

src/Symfony/Component/Form/Tests/Fixtures/foo2

Whitespace-only changes.

src/Symfony/Component/Form/Tests/Fixtures/foo3

Whitespace-only changes.

src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ protected function getRequestHandler()
206206
return new NativeRequestHandler($this->serverParams);
207207
}
208208

209-
protected function getMockFile()
209+
protected function getMockFile($suffix = '')
210210
{
211211
return array(
212-
'name' => 'upload.txt',
212+
'name' => 'upload'.$suffix.'.txt',
213213
'type' => 'text/plain',
214-
'tmp_name' => 'owfdskjasdfsa',
214+
'tmp_name' => 'owfdskjasdfsa'.$suffix,
215215
'error' => UPLOAD_ERR_OK,
216216
'size' => 100,
217217
);

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ public function prepare(Request $request)
195195
$path = $this->file->getRealPath();
196196
if (strtolower($type) == 'x-accel-redirect') {
197197
// Do X-Accel-Mapping substitutions.
198+
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
198199
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
199200
$mapping = explode('=', $mapping, 2);
200201

201202
if (2 == count($mapping)) {
202-
$location = trim($mapping[0]);
203-
$pathPrefix = trim($mapping[1]);
203+
$pathPrefix = trim($mapping[0]);
204+
$location = trim($mapping[1]);
204205

205206
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
206207
$path = $location.substr($path, strlen($pathPrefix));

0 commit comments

Comments
 (0)