8000 Merge branch '2.3' into 2.6 · rubenrua/symfony@c9da1ae · GitHub
[go: up one dir, main page]

Skip to content

Commit c9da1ae

Browse files< 10000 /span>
Merge branch '2.3' into 2.6
* 2.3: [Form] NativeRequestHandler file handling fix [HttpKernel] Throw double-bounce exceptions minor symfony#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));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public function testAcceptRangeNotOverriden()
230230
public function getSampleXAccelMappings()
231231
{
232232
return array(
233-
array('/var/www/var/www/files/foo.txt', '/files/=/var/www/', '/files/var/www/files/foo.txt'),
234-
array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'),
233+
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
234+
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
235235
);
236236
}
237237

src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public function onKernelException(GetResponseForExceptionEvent $event)
5757
try {
5858
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
5959
} catch (\Exception $e) {
60-
$this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
60+
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
6161

6262
// set handling to false otherwise it wont be able to handle further more
6363
$handling = false;
6464

65-
// re-throw the exception from within HttpKernel as this is a catch-all
66-
return;
65+
// throwing $e, not $exception, is on purpose: fixing error handling code paths is the most important
66+
throw $e;
6767
}
6868

6969
$event->setResponse($response);
@@ -81,7 +81,7 @@ public static function getSubscribedEvents()
8181
/**
8282
* Logs an exception.
8383
*
84-
* @param \Exception $exception The original \Exception instance
84+
* @param \Exception $exception The \Exception instance
8585
* @param string $message 10000 The error message to log
8686
* @param bool $original False when the handling of the exception thrown another exception
8787
*/

src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public function testHandleWithoutLogger($event, $event2)
5454

5555
try {
5656
$l->onKernelException($event2);
57-
} catch (\Exception $e) {
58-
$this->assertSame('foo', $e->getMessage());
57+
$this->fail('RuntimeException expected');
58+
} catch (\RuntimeException $e) {
59+
$this->assertSame('bar', $e->getMessage());
5960
}
6061
}
6162

@@ -73,8 +74,9 @@ public function testHandleWithLogger($event, $event2)
7374

7475
try {
7576
$l->onKernelException($event2);
76-
} catch (\Exception $e) {
77-
$this->assertSame('foo', $e->getMessage());
77+
$this->fail('RuntimeException expected');
78+
} catch (\RuntimeException $e) {
79+
$this->assertSame('bar', $e->getMessage());
7880
}
7981

8082
$this->assertEquals(3, $logger->countErrors());
@@ -137,6 +139,6 @@ class TestKernelThatThrowsException implements HttpKernelInterface
137139
{
138140
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
139141
{
140-
throw new \Exception('bar');
142+
throw new \RuntimeException('bar');
141143
}
142144
}

0 commit comments

Comments
 (0)
0