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 = $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.

0 commit comments

Comments
 (0)