8000 Merge branch '3.4' into 4.0 · alex-dev/symfony@e0ce427 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0ce427

Browse files
Merge branch '3.4' into 4.0
* 3.4: [HttpKernel] Fixed invalid REMOTE_ADDR in inline subrequest when configuring trusted proxy with subnet [FrameworkBundle] fixed guard event names for transitions [DI] Improve class named servics error message [HttpFoundation] fixed using _method parameter with invalid type [Intl] Replace svn with git in the icu data update script [HttpFoundation] Fix Cookie::isCleared
2 parents 4fadd36 + 7e3603d commit e0ce427

File tree

17 files changed

+306
-270
lines changed

17 files changed

+306
-270
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
525525
$guard = new Definition(Workflow\EventListener\GuardListener::class);
526526
$guard->setPrivate(true);
527527
$configuration = array();
528-
foreach ($workflow['transitions'] as $transitionName => $config) {
528+
foreach ($workflow['transitions'] as $config) {
529+
$transitionName = 9E12 $config['name'];
530+
529531
if (!isset($config['guard'])) {
530532
continue;
531533
}

src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public function process(ContainerBuilder $container)
4848
throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
4949
}
5050
if (class_exists($id) || interface_exists($id, false)) {
51+
if (0 === strpos($id, '\\') && 1 < substr_count($id, '\\')) {
52+
throw new RuntimeException(sprintf(
53+
'The definition for "%s" has no class attribute, and appears to reference a class or interface. '
54+
.'Please specify the class attribute explicitly or remove the leading backslash by renaming '
55+
.'the service to "%s" to get rid of this error.',
56+
$id, substr($id, 1)
57+
));
58+
}
59+
5160
throw new RuntimeException(sprintf(
5261
'The definition for "%s" has no class attribute, and appears to reference a '
5362
.'class or interface in the global namespace. Leaving out the "class" attribute '

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,30 @@ public function testNoClassFromGlobalNamespaceClassId()
12381238
$container->compile();
12391239
}
12401240

1241+
/**
1242+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
1243+
* @expectedExceptionMessage The definition for "\DateTime" has no class attribute, and appears to reference a class or interface in the global namespace.
1244+
*/
1245+
public function testNoClassFromGlobalNamespaceClassIdWithLeadingSlash()
1246+
{
1247+
$container = new ContainerBuilder();
1248+
1249+
$container->register('\\'.\DateTime::class);
1250+
$container->compile();
1251+
}
1252+
1253+
/**
1254+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
1255+
* @expectedExceptionMessage The definition for "\Symfony\Component\DependencyInjection\Tests\FooClass" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "Symfony\Component\DependencyInjection\Tests\FooClass" to get rid of this error.
1256+
*/
1257+
public function testNoClassFromNamespaceClassIdWithLeadingSlash()
1258+
{
1259+
$container = new ContainerBuilder();
1260+
1261+
$container->register('\\'.FooClass::class);
1262+
$container->compile();
1263+
}
1264+
12411265
/**
12421266
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
12431267
* @expectedExceptionMessage The definition for "123_abc" has no class.

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function isHttpOnly()
266266
*/
267267
public function isCleared()
268268
{
269-
return $this->expire < time();
269+
return 0 !== $this->expire && $this->expire < time();
270270
}
271271

272272
/**

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,10 @@ public function getMethod()
12211221
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
12221222
$this->method = strtoupper($method);
12231223
} elseif (self::$httpMethodParameterOverride) {
1224-
$this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
1224+
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1225+
if (\is_string($method)) {
1226+
$this->method = strtoupper($method);
1227+
}
12251228
}
12261229
}
12271230
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ public function testCookieIsCleared()
154154
$cookie = new Cookie('foo', 'bar', time() - 20);
155155

156156
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
157+
158+
$cookie = new Cookie('foo', 'bar');
159+
160+
$this->assertFalse($cookie->isCleared());
161+
162+
$cookie = new Cookie('foo', 'bar', 0);
163+
164+
$this->assertFalse($cookie->isCleared());
165+
166+
$cookie = new Cookie('foo', 'bar', -1);
167+
168+
$this->assertFalse($cookie->isCleared());
157169
}
158170

159171
public function testToString()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ public function testGetSetMethod()
848848
$request->setMethod('POST');
849849
$request->headers->set('X-HTTP-METHOD-OVERRIDE', 'delete');
850850
$this->assertEquals('DELETE', $request->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override if defined and POST');
851+
852+
$request = new Request();
853+
$request->setMethod('POST');
854+
$request->query->set('_method', array('delete', 'patch'));
855+
$this->assertSame('POST', $request->getMethod(), '->getMethod() returns the request method if invalid type is defined in query');
851856
}
852857

853858
/**

src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ protected function createSubRequest($uri, Request $request)
115115
$server['HTTP_X_FORWARDED_FOR'] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp();
116116
}
117117

118-
$trustedProxies = Request::getTrustedProxies();
119-
$server['REMOTE_ADDR'] = $trustedProxies ? reset($trustedProxies) : '127.0.0.1';
118+
$server['REMOTE_ADDR'] = $this->resolveTrustedProxy();
120119

121120
unset($server['HTTP_IF_MODIFIED_SINCE']);
122121
unset($server['HTTP_IF_NONE_MATCH']);
@@ -133,6 +132,17 @@ protected function createSubRequest($uri, Request $request)
133132
return $subRequest;
134133
}
135134

135+
private function resolveTrustedProxy()
136+
{
137+
if (!$trustedProxies = Request::getTrustedProxies()) {
138+
return '127.0.0.1';
139+
}
140+
141+
$firstTrustedProxy = reset($trustedProxies);
142+
143+
return false !== ($i = strpos($firstTrustedProxy, '/')) ? substr($firstTrustedProxy, 0, $i) : $firstTrustedProxy;
144+
}
145+
136146
/**
137147
* {@inheritdoc}
138148
*/

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ public function testFirstTrustedProxyIsSetAsRemote()
195195
Request::setTrustedProxies(array(), -1);
196196
}
197197

198+
public function testIpAddressOfRangedTrustedProxyIsSetAsRemote()
199+
{
200+
$expectedSubRequest = Request::create('/');
201+
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
202+
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');
203+
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
204+
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
205+
206+
Request::setTrustedProxies(array('1.1.1.1/24'), -1);
207+
208+
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
209+
210+
$request = Request::create('/');
211+
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
212+
$strategy->render('/', $request);
213+
214+
Request::setTrustedProxies(array(), -1);
215+
}
216+
198217
/**
199218
* Creates a Kernel expecting a request equals to $request
200219
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.

src/Symfony/Component/Intl/Resources/bin/icu.ini

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Symfony/Component/Intl/Resources/bin/update-data.php

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
2626
use Symfony\Component\Intl\Intl;
2727
use Symfony\Component\Intl\Locale;
28-
use Symfony\Component\Intl\Util\IcuVersion;
29-
use Symfony\Component\Intl\Util\SvnRepository;
28+
use Symfony\Component\Intl\Util\GitRepository;
3029

3130
require_once __DIR__.'/common.php';
3231
require_once __DIR__.'/autoload.php';
@@ -40,7 +39,7 @@
4039
4140
Updates the ICU data for Symfony to the latest version of ICU.
4241
43-
If you downloaded the SVN repository before, you can pass the path to the
42+
If you downloaded the git repository before, you can pass the path to the
4443
repository source in the first optional argument.
4544
4645
If you also built the repository before, you can pass the directory where that
@@ -64,36 +63,30 @@
6463
bailout('The intl extension for PHP is not installed.');
6564
}
6665

67-
$filesystem = new Filesystem();
68-
$urls = parse_ini_file(__DIR__.'/icu.ini');
69-
70-
echo "icu.ini parsed. Available versions:\n";
66+
if ($argc >= 2) {
67+
$repoDir = $argv[1];
68+
$git = new GitRepository($repoDir);
7169

72-
$maxVersion = 0;
70+
echo "Using the existing git repository at {$repoDir}.\n";
71+
} else {
72+
echo "Starting git clone. This may take a while...\n";
7373

74-
foreach ($urls as $urlVersion => $url) {
75-
$maxVersion = IcuVersion::compare($maxVersion, $urlVersion, '<')
76-
? $urlVersion
77-
: $maxVersion;
74+
$repoDir = sys_get_temp_dir().'/icu-data';
75+
$git = GitRepository::download('https://github.com/unicode-org/icu.git', $repoDir);
7876

79-
echo " $urlVersion\n";
77+
echo "Git clone to {$repoDir} complete.\n";
8078
}
8179

82-
$shortIcuVersion = strip_minor_versions($maxVersion);
83-
84-
if ($argc >= 2) {
85-
$sourceDir = $argv[1];
86-
$svn = new SvnRepository($sourceDir);
87-
88-
echo "Using existing SVN repository at {$sourceDir}.\n";
89-
} else {
90-
echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n";
80+
$gitTag = $git->getLastTag(function ($tag) {
81+
return preg_match('#^release-[0-9]{1,}-[0-9]{1}$#', $tag);
82+
});
83+
$shortIcuVersion = strip_minor_versions(preg_replace('#release-([0-9]{1,})-([0-9]{1,})#', '$1.$2', $gitTag));
9184

92-
$sourceDir = sys_get_temp_dir().'/icu-data/'.$shortIcuVersion.'/source';
93-
$svn = SvnRepository::download($urls[$shortIcuVersion], $sourceDir);
85+
echo "Checking out `{$gitTag}` for version `{$shortIcuVersion}`...\n";
86+
$git->checkout('tags/'.$gitTag);
9487

95-
echo "SVN checkout to {$sourceDir} complete.\n";
96-
}
88+
$filesystem = new Filesystem();
89+
$sourceDir = $repoDir.'/icu4c/source';
9790

9891
if ($argc >= 3) {
9992
$buildDir = $argv[2];
@@ -265,23 +258,23 @@
265258

266259
echo "Resource bundle compilation complete.\n";
267260

268-
$svnInfo = <<<SVN_INFO
269-
SVN information
261+
$gitInfo = <<<GIT_INFO
262+
Git information
270263
===============
271264
272-
URL: {$svn->getUrl()}
273-
Revision: {$svn->getLastCommit()->getRevision()}
274-
Author: {$svn->getLastCommit()->getAuthor()}
275-
Date: {$svn->getLastCommit()->getDate()}
265+
URL: {$git->getUrl()}
266+
Revision: {$git->getLastCommitHash()}
267+
Author: {$git->getLastAuthor()}
268+
Date: {$git->getLastAuthoredDate()->format('c')}
276269
277-
SVN_INFO;
270+
GIT_INFO;
278271

279272
foreach ($targetDirs as $targetDir) {
280-
$svnInfoFile = $targetDir.'/svn-info.txt';
273+
$gitInfoFile = $targetDir.'/git-info.txt';
281274

282-
file_put_contents($svnInfoFile, $svnInfo);
275+
file_put_contents($gitInfoFile, $gitInfo);
283276

284-
echo "Wrote $svnInfoFile.\n";
277+
echo "Wrote $gitInfoFile.\n";
285278

286279
$versionFile = $targetDir.'/version.txt';
287280

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Git information
2+
===============
3+
4+
URL: https://github.com/unicode-org/icu.git
5+
Revision: 4a3ba8eee90ea1414d4f7ee36563e6c9b28fda96
6+
Author: Yoshito Umaoka
7+
Date: 2018-06-20T05:34:56+00:00

src/Symfony/Component/Intl/Resources/data/svn-info.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Intl\Tests\Util;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Filesystem\Filesystem;
16+
use Symfony\Component\Intl\Util\GitRepository;
17+
18+
/**
19+
* @group intl-data
20+
*/
21+
class GitRepositoryTest extends TestCase
22+
{
23+
private $targetDir;
24+
25+
const REPO_URL = 'https://github.com/symfony/intl.git';
26+
27+
/**
28+
* @before
29+
* @after
30+
*/
31+
protected function cleanup()
32+
{
33+
$this->targetDir = sys_get_temp_dir().'/GitRepositoryTest/source';
34+
35+
$fs = new Filesystem();
36+
$fs->remove($this->targetDir);
37+
}
38+
39+
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
40+
{
41+
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
42+
43+
@mkdir($this->targetDir, '0777', true);
44+
45+
new GitRepository($this->targetDir);
46+
}
47+
48+
public function testItClonesTheRepository()
49+
{
50+
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
51+
52+
$this->assertInstanceOf('Symfony\Component\Intl\Util\GitRepository', $git);
53+
$this->assertDirectoryExists($this->targetDir.'/.git');
54+
$this->assertSame($this->targetDir, $git->getPath());
55+
$this->assertSame(self::REPO_URL, $git->getUrl());
56+
$this->assertRegExp('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
57+
$this->assertNotEmpty($git->getLastAuthor());
58+
$this->assertInstanceOf('DateTime', $git->getLastAuthoredDate());
59+
$this->assertStringMatchesFormat('v%s', $git->getLastTag());
60+
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); }));
61+
}
62+
63+
public function testItCheckoutsToTheLastTag()
64+
{
65+
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
66+
$lastCommitHash = $git->getLastCommitHash();
67+
$lastV3Tag = $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); });
68+
69+
$git->checkout($lastV3Tag);
70+
71+
$this->assertNotEquals($lastCommitHash, $git->getLastCommitHash());
72+
}
73+
}

0 commit comments

Comments
 (0)
0