Skip to content

Commit 1fa24cb

Browse files
author
Robin Chalas
committed
Merge branch '3.4' into 4.1
* 3.4: properly fix tests on PHP 5 fix tests on PHP 5 bug symfony#29697 [DI] Fixed wrong factory method in exception (Wojciech Gorczyca) Changed gender choice types to color remove no longer needed PHP version checks Fixed groupBy argument value in DefaultChoiceListFactoryTest [HttpKernel] Correctly Render Signed URIs Containing Fragments [HttpFoundation] Fix request uri when it starts with double slashes
2 parents 96b962d + 7af9c5d commit 1fa24cb

15 files changed

+134
-30
lines changed

.github/build-packages.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$mergeBase = trim(shell_exec(sprintf('git merge-base "%s" HEAD', array_shift($dirs))));
1717

1818
$packages = array();
19-
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
19+
$flags = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
2020

2121
foreach ($dirs as $k => $dir) {
2222
if (!system("git diff --name-only $mergeBase -- $dir", $exitStatus)) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
19-
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy;
19+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes;
2020
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
2121
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
2222
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
@@ -120,16 +120,16 @@ public function testArgumentNotFound()
120120

121121
/**
122122
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
123-
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummy::create()" has no argument named "$notFound". Check your service definition.
123+
* @expectedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\TestDefinition1": method "Symfony\Component\DependencyInjection\Tests\Fixtures\FactoryDummyWithoutReturnTypes::createTestDefinition1()" has no argument named "$notFound". Check your service definition.
124124
*/
125125
public function testCorrectMethodReportedInException()
126126
{
127127
$container = new ContainerBuilder();
128128

129-
$container->register(FactoryDummy::class, FactoryDummy::class);
129+
$container->register(FactoryDummyWithoutReturnTypes::class, FactoryDummyWithoutReturnTypes::class);
130130

131131
$definition = $container->register(TestDefinition1::class, TestDefinition1::class);
132-
$definition->setFactory(array(FactoryDummy::class, 'create'));
132+
$definition->setFactory(array(FactoryDummyWithoutReturnTypes::class, 'createTestDefinition1'));
133133
$definition->setArguments(array('$notFound' => '123'));
134134

135135
$pass = new ResolveNamedArgumentsPass();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\DependencyInjection\Tests\Fixtures;
13+
14+
class FactoryDummyWithoutReturnTypes
15+
{
16+
public function createTestDefinition1()
17+
{
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\DependencyInjection\Tests\Fixtures;
13+
14+
use Symfony\Component\DependencyInjection\Definition;
15+
16+
class TestDefinition1 extends Definition
17+
{
18+
}

src/Symfony/Component/Form/Forms.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* ->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
2727
* ->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
2828
* ->add('age', 'Symfony\Component\Form\Extension\Core\Type\IntegerType')
29-
* ->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
30-
* 'choices' => array('Male' => 'm', 'Female' => 'f'),
29+
* ->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
30+
* 'choices' => array('Red' => 'r', 'Blue' => 'b'),
3131
* ))
3232
* ->getForm();
3333
*

src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function testCreateViewFlatGroupByEmpty()
443443
array($this->obj2, $this->obj3),
444444
null, // label
445445
null, // index
446-
array() // ignored
446+
null // group
447447
);
448448

449449
$this->assertFlatView($view);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testArrayBasedForm()
3131
$form = $this->factory->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType')
3232
->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
3333
->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
34-
->add('gender', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
35-
'choices' => array('male' => 'Male', 'female' => 'Female'),
34+
->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
35+
'choices' => array('red' => 'Red', 'blue' => 'Blue'),
3636
'required' => false,
3737
))
3838
->add('age', 'Symfony\Component\Form\Extension\Core\Type\NumberType')

src/Symfony/Component/HttpFoundation/Request.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -1696,15 +1696,23 @@ protected function prepareRequestUri()
16961696
} elseif ($this->server->has('REQUEST_URI')) {
16971697
$requestUri = $this->server->get('REQUEST_URI');
16981698

1699-
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
1700-
$uriComponents = parse_url($requestUri);
1699+
if ('' !== $requestUri && '/' === $requestUri[0]) {
1700+
// To only use path and query remove the fragment.
1701+
if (false !== $pos = strpos($requestUri, '#')) {
1702+
$requestUri = substr($requestUri, 0, $pos);
1703+
}
1704+
} else {
1705+
// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
1706+
// only use URL path.
1707+
$uriComponents = parse_url($requestUri);
17011708

1702-
if (isset($uriComponents['path'])) {
1703-
$requestUri = $uriComponents['path'];
1704-
}
1709+
if (isset($uriComponents['path'])) {
1710+
$requestUri = $uriComponents['path'];
1711+
}
17051712

1706-
if (isset($uriComponents['query'])) {
1707-
$requestUri .= '?'.$uriComponents['query'];
1713+
if (isset($uriComponents['query'])) {
1714+
$requestUri .= '?'.$uriComponents['query'];
1715+
}
17081716
}
17091717
} elseif ($this->server->has('ORIG_PATH_INFO')) {
17101718
// IIS 5.0, PHP as CGI

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

+49
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,55 @@ public function testCreateWithRequestUri()
283283
$this->assertEquals('http://test.com/foo', $request->getUri());
284284
}
285285

286+
/**
287+
* @dataProvider getRequestUriData
288+
*/
289+
public function testGetRequestUri($serverRequestUri, $expected, $message)
290+
{
291+
$request = new Request();
292+
$request->server->add(array(
293+
'REQUEST_URI' => $serverRequestUri,
294+
295+
// For having http://test.com
296+
'SERVER_NAME' => 'test.com',
297+
'SERVER_PORT' => 80,
298+
));
299+
300+
$this->assertSame($expected, $request->getRequestUri(), $message);
301+
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
302+
}
303+
304+
public function getRequestUriData()
305+
{
306+
$message = 'Do not modify the path.';
307+
yield array('/foo', '/foo', $message);
308+
yield array('//bar/foo', '//bar/foo', $message);
309+
yield array('///bar/foo', '///bar/foo', $message);
310+
311+
$message = 'Handle when the scheme, host are on REQUEST_URI.';
312+
yield array('http://test.com/foo?bar=baz', '/foo?bar=baz', $message);
313+
314+
$message = 'Handle when the scheme, host and port are on REQUEST_URI.';
315+
yield array('http://test.com:80/foo', '/foo', $message);
316+
yield array('https://test.com:8080/foo', '/foo', $message);
317+
yield array('https://test.com:443/foo', '/foo', $message);
318+
319+
$message = 'Fragment should not be included in the URI';
320+
yield array('http://test.com/foo#bar', '/foo', $message);
321+
yield array('/foo#bar', '/foo', $message);
322+
}
323+
324+
public function testGetRequestUriWithoutRequiredHeader()
325+
{
326+
$expected = '';
327+
328+
$request = new Request();
329+
330+
$message = 'Fallback to empty URI when headers are missing.';
331+
$this->assertSame($expected, $request->getRequestUri(), $message);
332+
$this->assertSame($expected, $request->server->get('REQUEST_URI'), 'Normalize the request URI.');
333+
}
334+
286335
public function testCreateCheckPrecedence()
287336
{
288337
// server is used by default

src/Symfony/Component/HttpKernel/Tests/DataCollector/DumpDataCollectorTest.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ public function testFlushNothingWhenDataDumperIsProvided()
144144
$collector->dump($data);
145145
$line = __LINE__ - 1;
146146
$output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
147-
if (\PHP_VERSION_ID >= 50400) {
148-
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
149-
} else {
150-
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
151-
}
147+
148+
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
152149

153150
ob_start();
154151
$collector->__destruct();

src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRenderControllerReference()
6060
$altReference = new ControllerReference('alt_controller', array(), array());
6161

6262
$this->assertEquals(
63-
'<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller&_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D" />',
63+
'<esi:include src="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />',
6464
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
6565
);
6666
}

src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRenderWithControllerAndSigner()
3232
{
3333
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
3434

35-
$this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
35+
$this->assertEquals('<hx:include src="/_fragment?_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D&amp;_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
3636
}
3737

3838
public function testRenderWithUri()

src/Symfony/Component/HttpKernel/Tests/Fragment/SsiFragmentRendererTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testRenderControllerReference()
5151
$altReference = new ControllerReference('alt_controller', array(), array());
5252

5353
$this->assertEquals(
54-
'<!--#include virtual="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" -->',
54+
'<!--#include virtual="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" -->',
5555
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
5656
);
5757
}

src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function testSign()
2121
$signer = new UriSigner('foobar');
2222

2323
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
24-
$this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
24+
$this->assertContains('?_hash=', $signer->sign('http://example.com/foo?foo=bar'));
25+
$this->assertContains('&foo=', $signer->sign('http://example.com/foo?foo=bar'));
2526
}
2627

2728
public function testCheck()
@@ -45,7 +46,7 @@ public function testCheckWithDifferentArgSeparator()
4546
$signer = new UriSigner('foobar');
4647

4748
$this->assertSame(
48-
'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
49+
'http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar',
4950
$signer->sign('http://example.com/foo?foo=bar&baz=bay')
5051
);
5152
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
@@ -61,4 +62,15 @@ public function testCheckWithDifferentParameter()
6162
);
6263
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
6364
}
65+
66+
public function testSignerWorksWithFragments()
67+
{
68+
$signer = new UriSigner('foobar');
69+
70+
$this->assertSame(
71+
'http://example.com/foo?_hash=EhpAUyEobiM3QTrKxoLOtQq5IsWyWedoXDPqIjzNj5o%3D&bar=foo&foo=bar#foobar',
72+
$signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')
73+
);
74+
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?bar=foo&foo=bar#foobar')));
75+
}
6476
}

src/Symfony/Component/HttpKernel/UriSigner.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public function sign($uri)
5151
}
5252

5353
$uri = $this->buildUrl($url, $params);
54+
$params[$this->parameter] = $this->computeHash($uri);
5455

55-
return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri);
56+
return $this->buildUrl($url, $params);
5657
}
5758

5859
/**
@@ -75,15 +76,15 @@ public function check($uri)
7576
return false;
7677
}
7778

78-
$hash = urlencode($params[$this->parameter]);
79+
$hash = $params[$this->parameter];
7980
unset($params[$this->parameter]);
8081

8182
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
8283
}
8384

8485
private function computeHash($uri)
8586
{
86-
return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
87+
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
8788
}
8889

8990
private function buildUrl(array $url, array $params = array())

0 commit comments

Comments
 (0)