Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8d96861

Browse filesBrowse files
Merge branch '4.2'
* 4.2: Revert "bug #30423 [Security] Rework firewall's access denied rule (dimabory)" [FrameworkBundle] minor: remove a typo from changelog [VarDumper] fix tests with ICU 64.1 [VarDumper][Ldap] relax some locally failing tests [Validator] #30192 Added the missing translations for the Tagalog ("tl") locale. Make MimeTypeExtensionGuesser case insensitive Fix get session when the request stack is empty [Routing] fix trailing slash redirection with non-greedy trailing vars [FrameworkBundle] decorate the ValidatorBuilder's translator with LegacyTranslatorProxy
2 parents 899985e + 2d2ff38 commit 8d96861
Copy full SHA for 8d96861

File tree

19 files changed

+163
-76
lines changed
Filter options

19 files changed

+163
-76
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ CHANGELOG
166166
The default value will be `state_machine` in Symfony 4.0.
167167
* Deprecated the `CompilerDebugDumpPass` class
168168
* Deprecated the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
169-
* Added a new new version strategy option called json_manifest_path
169+
* Added a new version strategy option called "json_manifest_path"
170170
that allows you to use the `JsonManifestVersionStrategy`.
171171
* Added `Symfony\Bundle\FrameworkBundle\Controller\AbstractController`. It provides
172172
the same helpers as the `Controller` class, but does not allow accessing the dependency

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
use Symfony\Component\Validator\ConstraintValidatorInterface;
111111
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
112112
use Symfony\Component\Validator\ObjectInitializerInterface;
113+
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
113114
use Symfony\Component\WebLink\HttpHeaderSerializer;
114115
use Symfony\Component\Workflow;
115116
use Symfony\Component\Workflow\WorkflowInterface;
@@ -1208,6 +1209,12 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
12081209

12091210
$validatorBuilder = $container->getDefinition('validator.builder');
12101211

1212+
if (class_exists(LegacyTranslatorProxy::class)) {
1213+
$calls = $validatorBuilder->getMethodCalls();
1214+
$calls[1] = ['setTranslator', [new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])]];
1215+
$validatorBuilder->setMethodCalls($calls);
1216+
}
1217+
12111218
$container->setParameter('validator.translation_domain', $config['translation_domain']);
12121219

12131220
$files = ['xml' => [], 'yml' => []];

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
5656
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
5757
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
58+
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
5859
use Symfony\Component\Validator\Validation;
5960
use Symfony\Component\Workflow;
6061

@@ -882,7 +883,11 @@ public function testValidation()
882883
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
883884
$this->assertEquals([new Reference('validator.validator_factory')], $calls[0][1]);
884885
$this->assertSame('setTranslator', $calls[1][0]);
885-
$this->assertEquals([new Reference('translator')], $calls[1][1]);
886+
if (class_exists(LegacyTranslatorProxy::class)) {
887+
$this->assertEquals([new Definition(LegacyTranslatorProxy::class, [new Reference('translator')])], $calls[1][1]);
888+
} else {
889+
$this->assertEquals([new Reference('translator')], $calls[1][1]);
890+
}
886891
$this->assertSame('setTranslationDomain', $calls[2][0]);
887892
$this->assertSame(['%validator.translation_domain%'], $calls[2][1]);
888893
$this->assertSame('addXmlMappings', $calls[3][0]);

‎src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeExtensionGuesser.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,12 @@ class MimeTypeExtensionGuesser implements ExtensionGuesserInterface
814814
*/
815815
public function guess($mimeType)
816816
{
817-
return isset($this->defaultExtensions[$mimeType]) ? $this->defaultExtensions[$mimeType] : null;
817+
if (isset($this->defaultExtensions[$mimeType])) {
818+
return $this->defaultExtensions[$mimeType];
819+
}
820+
821+
$lcMimeType = strtolower($mimeType);
822+
823+
return isset($this->defaultExtensions[$lcMimeType]) ? $this->defaultExtensions[$lcMimeType] : null;
818824
}
819825
}

‎src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ public function testGuessClientExtensionWithIncorrectMimeType()
9494
$this->assertEquals('jpeg', $file->guessClientExtension());
9595
}
9696

97+
public function testCaseSensitiveMimeType()
98+
{
99+
$file = new UploadedFile(
100+
__DIR__.'/Fixtures/case-sensitive-mime-type.xlsm',
101+
'test.xlsm',
102+
'application/vnd.ms-excel.sheet.macroEnabled.12',
103+
null
104+
);
105+
106+
$this->assertEquals('xlsm', $file->guessClientExtension());
107+
}
108+
97109
public function testErrorIsOkByDefault()
98110
{
99111
$file = new UploadedFile(

‎src/Symfony/Component/HttpKernel/EventListener/SessionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/SessionListener.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ protected function getSession()
4040

4141
if ($this->container->has('session_storage')
4242
&& ($storage = $this->container->get('session_storage')) instanceof NativeSessionStorage
43-
&& $this->container->get('request_stack')->getMasterRequest()->isSecure()
43+
&& ($masterRequest = $this->container->get('request_stack')->getMasterRequest())
44+
&& $masterRequest->isSecure()
4445
) {
4546
$storage->setOptions(['cookie_secure' => true]);
4647
}

‎src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Component\DependencyInjection\Container;
1616
use Symfony\Component\DependencyInjection\ServiceLocator;
1717
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\RequestStack;
1819
use Symfony\Component\HttpFoundation\Response;
1920
use Symfony\Component\HttpFoundation\Session\Session;
21+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
2022
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
2123
use Symfony\Component\HttpKernel\Event\RequestEvent;
2224
use Symfony\Component\HttpKernel\Event\ResponseEvent;
@@ -41,8 +43,16 @@ public function testSessionIsSet()
4143
{
4244
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
4345

46+
$requestStack = $this->getMockBuilder(RequestStack::class)->getMock();
47+
$requestStack->expects($this->once())->method('getMasterRequest')->willReturn(null);
48+
49+
$sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock();
50+
$sessionStorage->expects($this->never())->method('setOptions')->with(['cookie_secure' => true]);
51+
4452
$container = new Container();
4553
$container->set('session', $session);
54+
$container->set('request_stack', $requestStack);
55+
$container->set('session_storage', $sessionStorage);
4656

4757
$request = new Request();
4858
$listener = new SessionListener($container);

‎src/Symfony/Component/Ldap/Tests/LdapTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Tests/LdapTestCase.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ class LdapTestCase extends TestCase
88
{
99
protected function getLdapConfig()
1010
{
11+
$h = @ldap_connect(getenv('LDAP_HOST'), getenv('LDAP_PORT'));
12+
13+
if (!$h || !@ldap_bind($h)) {
14+
$this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT');
15+
}
16+
17+
ldap_close($h);
18+
1119
return [
1220
'host' => getenv('LDAP_HOST'),
1321
'port' => getenv('LDAP_PORT'),

‎src/Symfony/Component/Mime/MimeTypes.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/MimeTypes.php
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
final class MimeTypes implements MimeTypesInterface
4040
{
4141
private $extensions = [];
42+
private $mimeTypes = [];
4243

4344
/**
4445
* @var MimeTypeGuesserInterface[]
@@ -50,6 +51,10 @@ public function __construct(array $map = [])
5051
{
5152
foreach ($map as $mimeType => $extensions) {
5253
$this->extensions[$mimeType] = $extensions;
54+
55+
foreach ($extensions as $extension) {
56+
$this->mimeTypes[$extension] = $mimeType;
57+
}
5358
}
5459
$this->registerGuesser(new FileBinaryMimeTypeGuesser());
5560
$this->registerGuesser(new FileinfoMimeTypeGuesser());
@@ -80,15 +85,23 @@ public function registerGuesser(MimeTypeGuesserInterface $guesser)
8085
*/
8186
public function getExtensions(string $mimeType): array
8287
{
83-
return $this->extensions[$mimeType] ?? self::$map[$mimeType] ?? [];
88+
if ($this->extensions) {
89+
$extensions = $this->extensions[$mimeType] ?? $this->extensions[$lcMimeType = strtolower($mimeType)] ?? null;
90+
}
91+
92+
return $extensions ?? self::$map[$mimeType] ?? self::$map[$lcMimeType ?? strtolower($mimeType)] ?? [];
8493
}
8594

8695
/**
8796
* {@inheritdoc}
8897
*/
8998
public function getMimeTypes(string $ext): array
9099
{
91-
return self::$reverseMap[$ext] ?? [];
100+
if ($this->mimeTypes) {
101+
$mimeTypes = $this->mimeTypes[$ext] ?? $this->mimeTypes[$lcExt = strtolower($ext)] ?? null;
102+
}
103+
104+
return $mimeTypes ?? self::$reverseMap[$ext] ?? self::$reverseMap[$lcExt ?? strtolower($ext)] ?? [];
92105
}
93106

94107
/**

‎src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,22 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
136136
}
137137

138138
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
139+
140+
if ($hasTrailingVar && ($hasTrailingSlash || '/' !== substr($matches[\count($vars)], -1)) && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
141+
if ($hasTrailingSlash) {
142+
$matches = $n;
143+
} else {
144+
$hasTrailingVar = false;
145+
}
146+
}
147+
139148
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
140149
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
141150
return $allow = $allowSchemes = [];
142151
}
143152
continue;
144153
}
145154

146-
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
147-
$matches = $n;
148-
}
149-
150155
foreach ($vars as $i => $v) {
151156
if (isset($matches[1 + $i])) {
152157
$ret[$v] = $matches[1 + $i];

‎src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/UrlMatcher.php
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
158158

159159
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && preg_match('#\{\w+\}/?$#', $route->getPath());
160160

161+
if ($hasTrailingVar && ($hasTrailingSlash || '/' !== substr($matches[(\count($matches) - 1) >> 1], -1)) && preg_match($regex, $trimmedPathinfo, $m)) {
162+
if ($hasTrailingSlash) {
163+
$matches = $m;
164+
} else {
165+
$hasTrailingVar = false;
166+
}
167+
}
168+
161169
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
162170
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
163171
return $this->allow = $this->allowSchemes = [];
@@ -166,10 +174,6 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
166174
continue;
167175
}
168176

169-
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $trimmedPathinfo, $m)) {
170-
$matches = $m;
171-
}
172-
173177
$hostMatches = [];
174178
if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
175179
continue;

‎src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public function testSlashAndVerbPrecedenceWithRedirection()
187187
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
188188
}
189189

190+
public function testNonGreedyTrailingRequirement()
191+
{
192+
$coll = new RouteCollection();
193+
$coll->add('a', new Route('/{a}', [], ['a' => '\d+']));
194+
195+
$matcher = $this->getUrlMatcher($coll);
196+
$matcher->expects($this->once())->method('redirect')->with('/123')->willReturn([]);
197+
198+
$this->assertEquals(['_route' => 'a', 'a' => '123'], $matcher->match('/123/'));
199+
}
200+
190201
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
191202
{
192203
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', [$routes, $context ?: new RequestContext()]);

‎src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
133133
} catch (\Exception $e) {
134134
$event->setException($e);
135135
}
136+
137+
return;
136138
}
137139

138140
if (null !== $this->logger) {
@@ -150,7 +152,7 @@ private function handleAccessDeniedException(GetResponseForExceptionEvent $event
150152
$subRequest = $this->httpUtils->createRequest($event->getRequest(), $this->errorPage);
151153
$subRequest->attributes->set(Security::ACCESS_DENIED_ERROR, $exception);
152154

153-
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST));
155+
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true));
154156
$event->allowCustomResponseCode();
155157
}
156158
} catch (\Exception $e) {

‎src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php
+7-56Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAn
131131
{
132132
$event = $this->createEvent($exception);
133133

134-
$listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $this->createCustomAccessDeniedHandler(new Response('error')));
134+
$accessDeniedHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface')->getMock();
135+
$accessDeniedHandler->expects($this->once())->method('handle')->will($this->returnValue(new Response('error')));
135136

137+
$listener = $this->createExceptionListener(null, $this->createTrustResolver(true), null, null, null, $accessDeniedHandler);
136138
$listener->onKernelException($event);
137139

138140
$this->assertEquals('error', $event->getResponse()->getContent());
@@ -146,48 +148,13 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
146148
{
147149
$event = $this->createEvent($exception);
148150

149-
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(false), null, $this->createEntryPoint());
150-
$listener->onKernelException($event);
151-
152-
$this->assertEquals('OK', $event->getResponse()->getContent());
153-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
154-
}
155-
156-
/**
157-
* @dataProvider getAccessDeniedExceptionProvider
158-
*/
159-
public function testAccessDeniedExceptionNotFullFledgedAndWithAccessDeniedHandlerAndWithoutErrorPage(\Exception $exception, \Exception $eventException = null)
160-
{
161-
$event = $this->createEvent($exception);
162-
163-
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(false), null, $this->createEntryPoint(), null, $this->createCustomAccessDeniedHandler(new Response('denied', 403)));
164-
$listener->onKernelException($event);
165-
166-
$this->assertEquals('denied', $event->getResponse()->getContent());
167-
$this->assertEquals(403, $event->getResponse()->getStatusCode());
168-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
169-
}
170-
171-
/**
172-
* @dataProvider getAccessDeniedExceptionProvider
173-
*/
174-
public function testAccessDeniedExceptionNotFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage(\Exception $exception, \Exception $eventException = null)
175-
{
176-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
177-
$kernel->expects($this->once())->method('handle')->will($this->returnValue(new Response('Unauthorized', 401)));
178-
179-
$event = $this->createEvent($exception, $kernel);
180-
181-
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
182-
$httpUtils->expects($this->once())->method('createRequest')->will($this->returnValue(Request::create('/error')));
151+
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
152+
$tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
183153

184-
$listener = $this->createExceptionListener($this->createTokenStorage(), $this->createTrustResolver(true), $httpUtils, null, '/error');
154+
$listener = $this->createExceptionListener($tokenStorage, $this->createTrustResolver(false), null, $this->createEntryPoint());
185155
$listener->onKernelException($event);
186156

187-
$this->assertTrue($event->isAllowingCustomResponseCode());
188-
189-
$this->assertEquals('Unauthorized', $event->getResponse()->getContent());
190-
$this->assertEquals(401, $event->getResponse()->getStatusCode());
157+
$this->assertEquals('OK', $event->getResponse()->getContent());
191158
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
192159
}
193160

@@ -202,22 +169,6 @@ public function getAccessDeniedExceptionProvider()
202169
];
203170
}
204171

205-
private function createTokenStorage()
206-
{
207-
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
208-
$tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
209-
210-
return $tokenStorage;
211-
}
212-
213-
private function createCustomAccessDeniedHandler(Response $response)
214-
{
215-
$accessDeniedHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface')->getMock();
216-
$accessDeniedHandler->expects($this->once())->method('handle')->will($this->returnValue($response));
217-
218-
return $accessDeniedHandler;
219-
}
220-
221172
private function createEntryPoint(Response $response = null)
222173
{
223174
$entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.