Skip to content

Commit 18495e7

Browse files
committed
Merge branch '2.1'
* 2.1: (29 commits) [DependencyInjection] fixed composer.json [Validator] Fix typos in validators.ru.xlf Edited some minor grammar and style errors in russian validation file Updated Bulgarian translation [Form] improve error message with a "hasser" hint for PropertyAccessDeniedException [Form] Updated checks for the ICU version from 4.5+ to 4.7+ due to test failures with ICU 4.6 [Form] simplified a test from previous merge Update src/Symfony/Component/Form/Extension/Core/Type/FileType.php fixed CS Xliff with other node than source or target are ignored small fix of symfony#5984 when the container param is not set Filesystem Component mirror symlinked directory fix [Process][Tests] fixed chainedCommandsOutput tests fixed CS Use better default ports in urlRedirectAction Add tests for urlRedirectAction info about session namespace fix upgrade info about locale Update src/Symfony/Component/DomCrawler/Tests/FormTest.php Update src/Symfony/Component/DomCrawler/Form.php ...
2 parents 7fce02c + 922c201 commit 18495e7

File tree

34 files changed

+602
-92
lines changed

34 files changed

+602
-92
lines changed

UPGRADE-2.1.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Therefore you should change the namespace of this bundle in your AppKernel.php:
3030

3131
Before: `new Symfony\Bundle\DoctrineBundle\DoctrineBundle()`
32+
3233
After: `new Doctrine\Bundle\DoctrineBundle\DoctrineBundle()`
3334

3435
### HttpFoundation
@@ -52,11 +53,6 @@
5253
default_locale: fr
5354
```
5455
55-
* The methods `getPathInfo()`, `getBaseUrl()` and `getBasePath()` of
56-
a `Request` now all return a raw value (vs a urldecoded value before). Any call
57-
to one of these methods must be checked and wrapped in a `rawurldecode()` if
58-
needed.
59-
6056
##### Retrieving the locale from a Twig template
6157
6258
Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}`
@@ -75,13 +71,11 @@
7571
7672
After: `$request->getLocale()`
7773
78-
### HttpFoundation
79-
80-
* The current locale for the user is not stored anymore in the session
74+
##### Simulate old behavior
8175
82-
You can simulate the old behavior by registering a listener that looks like
83-
the following if the parameter which handles the locale value in the
84-
request is `_locale`:
76+
You can simulate that the locale for the user is still stored in the session by
77+
registering a listener that looks like the following if the parameter which
78+
handles the locale value in the request is `_locale`:
8579
8680
```
8781
namespace XXX;
@@ -123,6 +117,11 @@
123117
}
124118
```
125119
120+
* The methods `getPathInfo()`, `getBaseUrl()` and `getBasePath()` of
121+
a `Request` now all return a raw value (vs a urldecoded value before). Any call
122+
to one of these methods must be checked and wrapped in a `rawurldecode()` if
123+
needed.
124+
126125
### Security
127126
128127
* `Symfony\Component\Security\Core\User\UserInterface::equals()` has moved to
@@ -1341,6 +1340,9 @@
13411340
13421341
### Session
13431342
1343+
* The namespace of the Session class changed from `Symfony\Component\HttpFoundation\Session`
1344+
to `Symfony\Component\HttpFoundation\Session\Session`.
1345+
13441346
* Using `get` to retrieve flash messages now returns an array.
13451347
13461348
##### Retrieving the flash messages from a Twig template

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
148148
$resolver->setNormalizers(array(
149149
'em' => $emNormalizer,
150150
));
151+
152+
$resolver->setAllowedTypes(array(
153+
'loader' => array('null', 'Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface'),
154+
));
151155
}
152156

153157
/**

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public function redirectAction($route, $permanent = false)
5757
* In case the path is empty, the status code will be 404 when permanent is false
5858
* and 410 otherwise.
5959
*
60-
* @param string $path The absolute path or URL to redirect to
61-
* @param Boolean $permanent Whether the redirection is permanent
62-
* @param Boolean $scheme The URL scheme (null to keep the current one)
63-
* @param integer $httpPort The HTTP port
64-
* @param integer $httpsPort The HTTPS port
60+
* @param string $path The absolute path or URL to redirect to
61+
* @param Boolean $permanent Whether the redirect is permanent or not
62+
* @param string|null $scheme The URL scheme (null to keep the current one)
63+
* @param integer|null $httpPort The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
64+
* @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
6565
*
6666
* @return Response A Response instance
6767
*/
68-
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
68+
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
6969
{
7070
if ('' == $path) {
7171
return new Response(null, $permanent ? 410 : 404);
@@ -89,10 +89,30 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht
8989
}
9090

9191
$port = '';
92-
if ('http' === $scheme && 80 != $httpPort) {
93-
$port = ':'.$httpPort;
94-
} elseif ('https' === $scheme && 443 != $httpsPort) {
95-
$port = ':'.$httpsPort;
92+
if ('http' === $scheme) {
93+
if (null === $httpPort) {
94+
if ('http' === $request->getScheme()) {
95+
$httpPort = $request->getPort();
96+
} elseif ($this->container->hasParameter('request_listener.http_port')) {
97+
$httpPort = $this->container->getParameter('request_listener.http_port');
98+
}
99+
}
100+
101+
if (null !== $httpPort && 80 != $httpPort) {
102+
$port = ":$httpPort";
103+
}
104+
} elseif ('https' === $scheme) {
105+
if (null === $httpsPort) {
106+
if ('https' === $request->getScheme()) {
107+
$httpsPort = $request->getPort();
108+
} elseif ($this->container->hasParameter('request_listener.https_port')) {
109+
$httpsPort = $this->container->getParameter('request_listener.https_port');
110+
}
111+
}
112+
113+
if (null !== $httpsPort && 443 != $httpsPort) {
114+
$port = ":$httpsPort";
115+
}
96116
}
97117

98118
$url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ public function testRoute($permanent, $expectedCode)
8787

8888
$returnResponse = $controller->redirectAction($route, $permanent);
8989

90-
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
91-
92-
$this->assertTrue($returnResponse->isRedirect($url));
90+
$this->assertRedirectUrl($returnResponse, $url);
9391
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
9492
}
9593

@@ -119,9 +117,143 @@ public function testFullURL()
119117
$controller = new RedirectController();
120118
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
121119

122-
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
123-
124-
$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
120+
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
125121
$this->assertEquals(302, $returnResponse->getStatusCode());
126122
}
123+
124+
public function testUrlRedirectDefaultPortParameters()
125+
{
126+
$host = 'www.example.com';
127+
$baseUrl = '/base';
128+
$path = '/redirect-path';
129+
$httpPort = 1080;
130+
$httpsPort = 1443;
131+
132+
$expectedUrl = "https://$host:$httpsPort$baseUrl$path";
133+
$request = $this->createRequestObject('http', $host, $httpPort, $baseUrl);
134+
$controller = $this->createRedirectController($request, null, $httpsPort);
135+
$returnValue = $controller->urlRedirectAction($path, false, 'https');
136+
$this->assertRedirectUrl($returnValue, $expectedUrl);
137+
138+
$expectedUrl = "http://$host:$httpPort$baseUrl$path";
139+
$request = $this->createRequestObject('https', $host, $httpPort, $baseUrl);
140+
$controller = $this->createRedirectController($request, $httpPort);
141+
$returnValue = $controller->urlRedirectAction($path, false, 'http');
142+
$this->assertRedirectUrl($returnValue, $expectedUrl);
143+
}
144+
145+
public function urlRedirectProvider()
146+
{
147+
return array(
148+
// Standard ports
149+
array('http', null, null, 'http', 80, ""),
150+
array('http', 80, null, 'http', 80, ""),
151+
array('https', null, null, 'http', 80, ""),
152+
array('https', 80, null, 'http', 80, ""),
153+
154+
array('http', null, null, 'https', 443, ""),
155+
array('http', null, 443, 'https', 443, ""),
156+
array('https', null, null, 'https', 443, ""),
157+
array('https', null, 443, 'https', 443, ""),
158+
159+
// Non-standard ports
160+
array('http', null, null, 'http', 8080, ":8080"),
161+
array('http', 4080, null, 'http', 8080, ":4080"),
162+
array('http', 80, null, 'http', 8080, ""),
163+
array('https', null, null, 'http', 8080, ""),
164+
array('https', null, 8443, 'http', 8080, ":8443"),
165+
array('https', null, 443, 'http', 8080, ""),
166+
167+
array('https', null, null, 'https', 8443, ":8443"),
168+
array('https', null, 4443, 'https', 8443, ":4443"),
169+
array('https', null, 443, 'https', 8443, ""),
170+
array('http', null, null, 'https', 8443, ""),
171+
array('http', 8080, 4443, 'https', 8443, ":8080"),
172+
array('http', 80, 4443, 'https', 8443, ""),
173+
);
174+
}
175+
176+
/**
177+
* @dataProvider urlRedirectProvider
178+
*/
179+
public function testUrlRedirect($scheme, $httpPort, $httpsPort, $requestScheme, $requestPort, $expectedPort)
180+
{
181+
$host = 'www.example.com';
182+
$baseUrl = '/base';
183+
$path = '/redirect-path';
184+
$expectedUrl = "$scheme://$host$expectedPort$baseUrl$path";
185+
186+
$request = $this->createRequestObject($requestScheme, $host, $requestPort, $baseUrl);
187+
$controller = $this->createRedirectController($request);
188+
189+
$returnValue = $controller->urlRedirectAction($path, false, $scheme, $httpPort, $httpsPort);
190+
$this->assertRedirectUrl($returnValue, $expectedUrl);
191+
}
192+
193+
private function createRequestObject($scheme, $host, $port, $baseUrl)
194+
{
195+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
196+
$request
197+
->expects($this->any())
198+
->method('getScheme')
199+
->will($this->returnValue($scheme));
200+
$request
201+
->expects($this->any())
202+
->method('getHost')
203+
->will($this->returnValue($host));
204+
$request
205+
->expects($this->any())
206+
->method('getPort')
207+
->will($this->returnValue($port));
208+
$request
209+
->expects($this->any())
210+
->method('getBaseUrl')
211+
->will($this->returnValue($baseUrl));
212+
213+
return $request;
214+
}
215+
216+
private function createRedirectController(Request $request, $httpPort = null, $httpsPort = null)
217+
{
218+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
219+
$container
220+
->expects($this->at(0))
221+
->method('get')
222+
->with($this->equalTo('request'))
223+
->will($this->returnValue($request));
224+
if (null !== $httpPort) {
225+
$container
226+
->expects($this->once())
227+
->method('hasParameter')
228+
->with($this->equalTo('request_listener.http_port'))
229+
->will($this->returnValue(true));
230+
$container
231+
->expects($this->once())
232+
->method('getParameter')
233+
->with($this->equalTo('request_listener.http_port'))
234+
->will($this->returnValue($httpPort));
235+
}
236+
if (null !== $httpsPort) {
237+
$container
238+
->expects($this->once())
239+
->method('hasParameter')
240+
->with($this->equalTo('request_listener.https_port'))
241+
->will($this->returnValue(true));
242+
$container
243+
->expects($this->once())
244+
->method('getParameter')
245+
->with($this->equalTo('request_listener.https_port'))
246+
->will($this->returnValue($httpsPort));
247+
}
248+
249+
$controller = new RedirectController();
250+
$controller->setContainer($container);
251+
252+
return $controller;
253+
}
254+
255+
public function assertRedirectUrl(Response $returnResponse, $expectedUrl)
256+
{
257+
$this->assertTrue($returnResponse->isRedirect($expectedUrl), "Expected: $expectedUrl\nGot: ".$returnResponse->headers->get('Location'));
258+
}
127259
}

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function createAuthorization($config, ContainerBuilder $container)
182182
$container,
183183
$access['path'],
184184
$access['host'],
185-
count($access['methods']) === 0 ? null : $access['methods'],
185+
$access['methods'],
186186
$access['ip']
187187
);
188188

@@ -589,7 +589,7 @@ private function createSwitchUserListener($container, $id, $config, $defaultProv
589589
return $switchUserListenerId;
590590
}
591591

592-
private function createRequestMatcher($container, $path = null, $host = null, $methods = null, $ip = null, array $attributes = array())
592+
private function createRequestMatcher($container, $path = null, $host = null, $methods = array(), $ip = null, array $attributes = array())
593593
{
594594
$serialized = serialize(array($path, $host, $methods, $ip, $attributes));
595595
$id = 'security.request_matcher.'.md5($serialized).sha1($serialized);
@@ -598,6 +598,10 @@ private function createRequestMatcher($container, $path = null, $host = null, $m
598598
return $this->requestMatchers[$id];
599599
}
600600

601+
if ($methods) {
602+
$methods = array_map('strtoupper', (array) $methods);
603+
}
604+
601605
// only add arguments that are necessary
602606
$arguments = array($path, $host, $methods, $ip, $attributes);
603607
while (count($arguments) > 0 && !end($arguments)) {

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
),
7171

7272
'access_control' => array(
73-
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https'),
73+
array('path' => '/blog/524', 'role' => 'ROLE_USER', 'requires_channel' => 'https', 'methods' => array('get', 'POST')),
7474
array('path' => '/blog/.*', 'role' => 'IS_AUTHENTICATED_ANONYMOUSLY'),
7575
),
7676

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<role id="ROLE_SUPER_ADMIN">ROLE_USER,ROLE_ADMIN,ROLE_ALLOWED_TO_SWITCH</role>
6060
<role id="ROLE_REMOTE">ROLE_USER,ROLE_ADMIN</role>
6161

62-
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" />
62+
<rule path="/blog/524" role="ROLE_USER" requires-channel="https" methods="get,POST" />
6363
<rule role='IS_AUTHENTICATED_ANONYMOUSLY' path="/blog/.*" />
6464
</config>
6565
</srv:container>

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ security:
5757
ROLE_REMOTE: ROLE_USER,ROLE_ADMIN
5858

5959
access_control:
60-
- { path: /blog/524, role: ROLE_USER, requires_channel: https }
60+
- { path: /blog/524, role: ROLE_USER, requires_channel: https, methods: [get, POST]}
6161
-
6262
path: /blog/.*
6363
role: IS_AUTHENTICATED_ANONYMOUSLY

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function testAccess()
102102
$matcherIds = array();
103103
foreach ($rules as $rule) {
104104
list($matcherId, $roles, $channel) = $rule;
105+
$requestMatcher = $container->getDefinition($matcherId);
105106

106107
$this->assertFalse(isset($matcherIds[$matcherId]));
107108
$matcherIds[$matcherId] = true;
@@ -110,9 +111,17 @@ public function testAccess()
110111
if (1 === $i) {
111112
$this->assertEquals(array('ROLE_USER'), $roles);
112113
$this->assertEquals('https', $channel);
114+
$this->assertEquals(
115+
array('/blog/524', null, array('GET', 'POST')),
116+
$requestMatcher->getArguments()
117+
);
113118
} elseif (2 === $i) {
114119
$this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles);
115120
$this->assertNull($channel);
121+
$this->assertEquals(
122+
array('/blog/.*'),
123+
$requestMatcher->getArguments()
124+
);
116125
}
117126
}
118127
}

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private function initialize()
367367
$xpath = new \DOMXPath($document);
368368

369369
foreach ($xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root) as $node) {
370-
if (!$node->hasAttribute('name')) {
370+
if (!$node->hasAttribute('name') || !$node->getAttribute('name')) {
371371
continue;
372372
}
373373

0 commit comments

Comments
 (0)