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

Skip to content

Commit 7e3603d

Browse files
Merge branch '2.8' into 3.4
* 2.8: [HttpKernel] Fixed invalid REMOTE_ADDR in inline subrequest when configuring trusted proxy with subnet [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 4081bc6 + 9d0ff4f commit 7e3603d

File tree

14 files changed

+279
-269
lines changed

14 files changed

+279
-269
lines changed

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
@@ -1353,7 +1353,10 @@ public function getMethod()
13531353
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
13541354
$this->method = strtoupper($method);
13551355
} elseif (self::$httpMethodParameterOverride) {
1356-
$this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
1356+
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1357+
if (\is_string($method)) {
1358+
$this->method = strtoupper($method);
1359+
}
13571360
}
13581361
}
13591362
}

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

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

159159
$this->assertTrue($cookie->isCleared(), '->isCleared() returns true if the cookie has expired');
160+
161+
$cookie = new Cookie('foo', 'bar');
162+
163+
$this->assertFalse($cookie->isCleared());
164+
165+
$cookie = new Cookie('foo', 'bar', 0);
166+
167+
$this->assertFalse($cookie->isCleared());
168+
169+
$cookie = new Cookie('foo', 'bar', -1);
170+
171+
$this->assertFalse($cookie->isCleared());
160172
}
161173

162174
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
@@ -126,8 +126,7 @@ protected function createSubRequest($uri, Request $request)
126126
// Do nothing
127127
}
128128

129-
$trustedProxies = Request::getTrustedProxies();
130-
$server['REMOTE_ADDR'] = $trustedProxies ? reset($trustedProxies) : '127.0.0.1';
129+
$server['REMOTE_ADDR'] = $this->resolveTrustedProxy();
131130

132131
unset($server['HTTP_IF_MODIFIED_SINCE']);
133132
unset($server['HTTP_IF_NONE_MATCH']);
@@ -144,6 +143,17 @@ protected function createSubRequest($uri, Request $request)
144143
return $subRequest;
145144
}
146145

146+
private function resolveTrustedProxy()
147+
{
148+
if (!$trustedProxies = Request::getTrustedProxies()) {
149+
return '127.0.0.1';
150+
}
151+
152+
$firstTrustedProxy = reset($trustedProxies);
153+
154+
return false !== ($i = strpos($firstTrustedProxy, '/')) ? substr($firstTrustedProxy, 0, $i) : $firstTrustedProxy;
155+
}
156+
147157
/**
148158
* {@inheritdoc}
149159
*/

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,25 @@ public function testFirstTrustedProxyIsSetAsRemote()
239239
Request::setTrustedProxies(array(), -1);
240240
}
241241

242+
public function testIpAddressOfRangedTrustedProxyIsSetAsRemote()
243+
{
244+
$expectedSubRequest = Request::create('/');
245+
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
246+
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');
247+
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
248+
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
249+
250+
Request::setTrustedProxies(array('1.1.1.1/24'), -1);
251+
252+
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
253+
254+
$request = Request::create('/');
255+
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
256+
$strategy->render('/', $request);
257+
258+
Request::setTrustedProxies(array(), -1);
259+
}
260+
242261
/**
243262
* Creates a Kernel expecting a request equals to $request
244263
* 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.

0 commit comments

Comments
 (0)
0