Skip to content

Commit 1d3f835

Browse files
Merge branch '4.0' into 4.1
* 4.0: [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 329d3f7 + e0ce427 commit 1d3f835

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
@@ -593,7 +593,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
593593
$guard = new Definition(Workflow\EventListener\GuardListener::class);
594594
$guard->setPrivate(true);
595595
$configuration = array();
596-
foreach ($workflow['transitions'] as $transitionName => $config) {
596+
foreach ($workflow['transitions'] as $config) {
597+
$transitionName = $config['name'];
598+
597599
if (!isset($config['guard'])) {
598600
continue;
599601
}

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
@@ -252,7 +252,7 @@ public function isHttpOnly()
252252
*/
253253
public function isCleared()
254254
{
255-
return $this->expire < time();
255+
return 0 !== $this->expire && $this->expire < time();
256256
}
257257

258258
/**

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,10 @@ public function getMethod()
12181218
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
12191219
$this->method = strtoupper($method);
12201220
} elseif (self::$httpMethodParameterOverride) {
1221-
$this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
1221+
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1222+
if (\is_string($method)) {
1223+
$this->method = strtoupper($method);
1224+
}
12221225
}
12231226
}
12241227
}

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
@@ -854,6 +854,11 @@ public function testGetSetMethod()
854854
$request->setMethod('POST');
855855
$request->headers->set('X-HTTP-METHOD-OVERRIDE', 'delete');
856856
$this->assertEquals('DELETE', $request->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override if defined and POST');
857+
858+
$request = new Request();
859+
$request->setMethod('POST');
860+
$request->query->set('_method', array('delete', 'patch'));
861+
$this->assertSame('POST', $request->getMethod(), '->getMethod() returns the request method if invalid type is defined in query');
857862
}
858863

859864
/**

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']);
@@ -136,6 +135,17 @@ protected function createSubRequest($uri, Request $request)
136135
return $subRequest;
137136
}
138137

138+
private function resolveTrustedProxy()
139+
{
140+
if (!$trustedProxies = Request::getTrustedProxies()) {
141+
return '127.0.0.1';
142+
}
143+
144+
$firstTrustedProxy = reset($trustedProxies);
145+
146+
return false !== ($i = strpos($firstTrustedProxy, '/')) ? substr($firstTrustedProxy, 0, $i) : $firstTrustedProxy;
147+
}
148+
139149
/**
140150
* {@inheritdoc}
141151
*/

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.

0 commit comments

Comments
 (0)