8000 Merge branch '2.7' · symfony/symfony@43e100b · GitHub
[go: up one dir, main page]

Skip to content

Commit 43e100b

Browse files
Merge branch '2.7'
* 2.7: [Form] NativeRequestHandler file handling fix [VarDumper] Workaround stringy numeric keys [HttpKernel] Throw double-bounce exceptions [FrameworkBundle] silence E_USER_DEPRECATED in insulated clients [minor] composer.json fix [minor] composer.json fix Fixed absolute_url for absolute paths 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 a01fd1b + 2b036ec commit 43e100b

File tree

18 files changed

+195
-34
lines changed

18 files changed

+195
-34
lines changed

src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public function generateAbsoluteUrl($path)
6767
$prefix = substr($prefix, 0, $pos).'/';
6868
}
6969

70-
$path = $prefix.$path;
70+
return $request->getUriForPath($prefix.$path);
7171
}
7272

73-
return $request->getUriForPath($path);
73+
return $request->getSchemeAndHttpHost().$path;
7474
}
7575

7676
/**

src/Symfony/Bridge/Twig/Tests/Extension/HttpFoundationExtensionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ public function getGenerateAbsoluteUrlData()
4343
);
4444
}
4545

46+
public function testGenerateAbsoluteUrlWithScriptFileName()
47+
{
48+
$request = Request::create('http://localhost/app/web/app_dev.php');
49+
$request->server->set('SCRIPT_FILENAME', '/var/www/app/web/app_dev.php');
50+
51+
$stack = new RequestStack();
52+
$stack->push($request);
53+
$extension = new HttpFoundationExtension($stack);
54+
55+
$this->assertEquals(
56+
'http://localhost/app/web/bundles/framework/css/structure.css',
57+
$extension->generateAbsoluteUrl('/app/web/bundles/framework/css/structure.css')
58+
);
59+
}
60+
4661
/**
4762
* @dataProvider getGenerateRelativePathData()
4863
*/

src/Symfony/Bundle/ 10000 FrameworkBundle/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function getScript($request)
165165
$code = <<<EOF
166166
<?php
167167
168-
error_reporting($errorReporting);
168+
error_reporting($errorReporting & ~E_USER_DEPRECATED);
169169
170170
if ('$autoloader') {
171171
require_once '$autoloader';

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 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
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,17 @@ protected function castObject(Stub $stub, $isNested)
211211
}
212212

213213
if ($classInfo[1]) {
214-
$a = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
214+
$p = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
215215
} else {
216-
$a = (array) $obj;
216+
$p = (array) $obj;
217217
}
218218

219-
foreach ($a as $k => $p) {
219+
$a = array();
220+
foreach ($p as $k => $p) {
220221
if (!isset($k[0]) || ("\0" !== $k[0] && !$classInfo[2]->hasProperty($k))) {
221-
unset($a[$k]);
222222
$a["\0+\0".$k] = $p;
223+
} else {
224+
$a[$k] = $p;
223225
}
224226
}
225227

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests;
13+
14+
use Symfony\Component\VarDumper\Cloner\VarCloner;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class VarClonerTest extends \PHPUnit_Framework_TestCase
20+
{
21+
public function testClone()
22+
{
23+
$json = json_decode('{"1":{"var":"val"},"2":{"var":"val"}}');
24+
25+
$cloner = new VarCloner();
26+
$clone = $cloner->cloneVar($json);
27+
28+
$expected = <<<EOTXT
29+
Symfony\Component\VarDumper\Cloner\Data Object
30+
(
31+
[data:Symfony\Component\VarDumper\Cloner\Data:private] => Array
32+
(
33+
[0] => Array
34+
(
35+
[0] => Symfony\Component\VarDumper\Cloner\Stub Object
36+
(
37+
[type] => object
38+
[class] => stdClass
39+
[value] =>
40+
[cut] => 0
41+
[handle] => %d
42+
[refCount] => 0
43+
[position] => 1
44+
)
45+
46+
)
47+
48+
[1] => Array
49+
(
50+
[\000+\0001] => Symfony\Component\VarDumper\Cloner\Stub Object
51+
(
52+
[type] => object
53+
[class] => stdClass
54+
[value] =>
55+
[cut] => 0
56+
[handle] => %d
57+
[refCount] => 0
58+
[position] => 2
59+
)
60+
61+
[\000+\0002] => Symfony\Component\VarDumper\Cloner\Stub Object
62+
(
63+
[type] => object
64+
[class] => stdClass
65+
[value] =>
66+
[cut] => 0
67+
[handle] => %d
68+
[refCount] => 0
69+
[position] => 3
70+
)
71+
72+
)
73+
74+
[2] => Array
75+
(
76+
[\000+\000var] => val
77+
)
78+
79+
[3] => Array
80+
(
81+
[\000+\000var] => val
82+
)
83+
84+
)
85+
86+
[maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20
87+
[maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1
88+
[useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1
89+
)
90+
91+
EOTXT;
92+
$this->assertStringMatchesFormat($expected, print_r($clone, true));
93+
}
94+
}

0 commit comments

Comments
 (0)
0