Skip to content

Commit 1552a16

Browse files
committed
Merge branch '2.2'
* 2.2: [Config] #7644 add tests for passing number looking attributes as strings [HttpFoundation][BrowserKit] fixed path when converting a cookie to a string [BrowserKit] removed dead code [HttpFoundation] fixed empty domain= in Cookie::__toString() fixed detection of secure cookies received over https [2.2] Pass ESI header to subrequests [Translation] removed an uneeded class property [Translation] removed unneeded getter/setter [Translator] added additional conversion for encodings other than utf-8 fixed source messages to accept pluralized messages [Validator][translation][japanese] add messages for new validator fix a DI circular reference recognition bug [HttpFoundation] fixed the creation of sub-requests under some circumstances for IIS Conflicts: src/Symfony/Component/HttpFoundation/Tests/CookieTest.php
2 parents 6290220 + e81f792 commit 1552a16

File tree

20 files changed

+241
-45
lines changed

20 files changed

+241
-45
lines changed

src/Symfony/Component/BrowserKit/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function request($method, $uri, array $parameters = array(), array $files
266266

267267
$response = $this->filterResponse($this->response);
268268

269-
$this->cookieJar->updateFromResponse($response);
269+
$this->cookieJar->updateFromResponse($response, $uri);
270270

271271
$this->redirect = $response->getHeader('Location');
272272

src/Symfony/Component/BrowserKit/Cookie.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function __toString()
9595
$cookie .= '; domain='.$this->domain;
9696
}
9797

98-
if ('/' !== $this->path) {
98+
if ($this->path) {
9999
$cookie .= '; path='.$this->path;
100100
}
101101

@@ -147,10 +147,9 @@ public static function fromString($cookie, $url = null)
147147
if ((false === $urlParts = parse_url($url)) || !isset($urlParts['host']) || !isset($urlParts['path'])) {
148148
throw new \InvalidArgumentException(sprintf('The URL "%s" is not valid.', $url));
149149
}
150-
$parts = array_merge($urlParts, $parts);
151150

152-
$values['domain'] = $parts['host'];
153-
$values['path'] = substr($parts['path'], 0, strrpos($parts['path'], '/'));
151+
$values['domain'] = $urlParts['host'];
152+
$values['path'] = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/'));
154153
}
155154

156155
foreach ($parts as $part) {

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ public function testRequestCookies()
205205
$this->assertEquals(array('foo' => 'bar'), $client->getCookieJar()->allValues('http://www.example.com/foo/foobar'), '->request() updates the CookieJar');
206206
}
207207

208+
public function testRequestSecureCookies()
209+
{
210+
$client = new TestClient();
211+
$client->setNextResponse(new Response('<html><a href="/foo">foo</a></html>', 200, array('Set-Cookie' => 'foo=bar; path=/; secure')));
212+
$client->request('GET', 'https://www.example.com/foo/foobar');
213+
214+
$this->assertTrue($client->getCookieJar()->get('foo', '/', 'www.example.com')->isSecure());
215+
}
216+
208217
public function testClick()
209218
{
210219
if (!class_exists('Symfony\Component\DomCrawler\Crawler')) {

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function testToFromString($cookie, $url = null)
2626
public function getTestsForToFromString()
2727
{
2828
return array(
29-
array('foo=bar'),
29+
array('foo=bar; path=/'),
3030
array('foo=bar; path=/foo'),
31-
array('foo=bar; domain=google.com'),
32-
array('foo=bar; domain=example.com; secure', 'https://example.com/'),
33-
array('foo=bar; httponly'),
31+
array('foo=bar; domain=google.com; path=/'),
32+
array('foo=bar; domain=example.com; path=/; secure', 'https://example.com/'),
33+
array('foo=bar; path=/; httponly'),
3434
array('foo=bar; domain=google.com; path=/foo; secure; httponly', 'https://google.com/'),
35-
array('foo=bar=baz'),
36-
array('foo=bar%3Dbaz'),
35+
array('foo=bar=baz; path=/'),
36+
array('foo=bar%3Dbaz; path=/'),
3737
);
3838
}
3939

@@ -67,17 +67,17 @@ public function getExpireCookieStrings()
6767

6868
public function testFromStringWithCapitalization()
6969
{
70-
$this->assertEquals('Foo=Bar', (string) Cookie::fromString('Foo=Bar'));
71-
$this->assertEquals('foo=bar; expires=Fri, 31 Dec 2010 23:59:59 GMT', (string) Cookie::fromString('foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT'));
72-
$this->assertEquals('foo=bar; domain=www.example.org; httponly', (string) Cookie::fromString('foo=bar; DOMAIN=www.example.org; HttpOnly'));
70+
$this->assertEquals('Foo=Bar; path=/', (string) Cookie::fromString('Foo=Bar'));
71+
$this->assertEquals('foo=bar; expires=Fri, 31 Dec 2010 23:59:59 GMT; path=/', (string) Cookie::fromString('foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT'));
72+
$this->assertEquals('foo=bar; domain=www.example.org; path=/; httponly', (string) Cookie::fromString('foo=bar; DOMAIN=www.example.org; HttpOnly'));
7373
}
7474

7575
public function testFromStringWithUrl()
7676
{
77-
$this->assertEquals('foo=bar; domain=www.example.com', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));
77+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));
7878
$this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::FromString('foo=bar', 'http://www.example.com/foo/bar'));
79-
$this->assertEquals('foo=bar; domain=www.example.com', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
80-
$this->assertEquals('foo=bar; domain=www.myotherexample.com', (string) Cookie::FromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
79+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
80+
$this->assertEquals('foo=bar; domain=www.myotherexample.com; path=/', (string) Cookie::FromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
8181
}
8282

8383
public function testFromStringThrowsAnExceptionIfCookieIsNotValid()

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ public function getDataForPhpize()
117117
array(100.0, '1e2'),
118118
array(-120.0, '-1.2E2'),
119119
array(-10100.1, '-10100.1'),
120-
array(-10100.1, '-10,100.1'),
120+
array('-10,100.1', '-10,100.1'),
121+
array('1234 5678 9101 1121 3141', '1234 5678 9101 1121 3141'),
122+
array('1,2,3,4', '1,2,3,4'),
123+
array('11,22,33,44', '11,22,33,44'),
124+
array('11,222,333,4', '11,222,333,4'),
125+
array('1,222,333,444', '1,222,333,444'),
126+
array('11,222,333,444', '11,222,333,444'),
127+
array('111,222,333,444', '111,222,333,444'),
128+
array('1111,2222,3333,4444,5555', '1111,2222,3333,4444,5555'),
121129
array('foo', 'foo'),
122130
);
123131
}

src/Symfony/Component/Config/Util/XmlUtils.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public static function phpize($value)
193193
return false;
194194
case is_numeric($value):
195195
return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
196-
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
197-
return floatval(str_replace(',', '', $value));
196+
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
197+
return floatval($value);
198198
default:
199199
return $value;
200200
}

src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ public function process(ContainerBuilder $container)
5656
private function checkOutEdges(array $edges)
5757
{
5858
foreach ($edges as $edge) {
59-
$node = $edge->getDestNode();
60-
$this->currentPath[] = $id = $node->getId();
59+
$node = $edge->getDestNode();
60+
$id = $node->getId();
61+
$searchKey = array_search($id, $this->currentPath);
62+
$this->currentPath[] = $id;
6163

62-
if ($this->currentId === $id) {
63-
throw new ServiceCircularReferenceException($this->currentId, $this->currentPath);
64+
if (false !== $searchKey) {
65+
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
6466
}
6567

6668
$this->checkOutEdges($node->getOutEdges());

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
2525
{
2626
/**
27-
* @expectedException \RuntimeException
27+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
2828
*/
2929
public function testProcess()
3030
{
@@ -36,7 +36,7 @@ public function testProcess()
3636
}
3737

3838
/**
39-
* @expectedException \RuntimeException
39+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
4040
*/
4141
public function testProcessWithAliases()
4242
{
@@ -49,7 +49,7 @@ public function testProcessWithAliases()
4949
}
5050

5151
/**
52-
* @expectedException \RuntimeException
52+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
5353
*/
5454
public function testProcessDetectsIndirectCircularReference()
5555
{
@@ -61,6 +61,19 @@ public function testProcessDetectsIndirectCircularReference()
6161
$this->process($container);
6262
}
6363

64+
/**
65+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
66+
*/
67+
public function testDeepCircularReference()
68+
{
69+
$container = new ContainerBuilder();
70+
$container->register('a')->addArgument(new Reference('b'));
71+
$container->register('b')->addArgument(new Reference('c'));
72+
$container->register('c')->addArgument(new Reference('b'));
73+
74+
$this->process($container);
75+
}
76+
6477
public function testProcessIgnoresMethodCalls()
6578
{
6679
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<parameter>on</parameter>
1717
<parameter>off</parameter>
1818
<parameter key="float">1.3</parameter>
19-
<parameter>1,000.3</parameter>
19+
<parameter>1000.3</parameter>
2020
<parameter>a string</parameter>
2121
<parameter type="collection">
2222
<parameter>foo</parameter>

src/Symfony/Component/HttpFoundation/Cookie.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ public function __toString()
9393
}
9494
}
9595

96-
if ('/' !== $this->path) {
96+
if ($this->path) {
9797
$str .= '; path='.$this->path;
9898
}
9999

100-
if (null !== $this->getDomain()) {
100+
if ($this->getDomain()) {
101101
$str .= '; domain='.$this->getDomain();
102102
}
103103

src/Symfony/Component/HttpFoundation/Request.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -1464,11 +1464,14 @@ protected function prepareRequestUri()
14641464
{
14651465
$requestUri = '';
14661466

1467-
if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
1467+
if ($this->headers->has('X_ORIGINAL_URL')) {
14681468
// IIS with Microsoft Rewrite Module
14691469
$requestUri = $this->headers->get('X_ORIGINAL_URL');
14701470
$this->headers->remove('X_ORIGINAL_URL');
1471-
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
1471+
$this->server->remove('HTTP_X_ORIGINAL_URL');
1472+
$this->server->remove('UNENCODED_URL');
1473+
$this->server->remove('IIS_WasUrlRewritten');
1474+
} elseif ($this->headers->has('X_REWRITE_URL')) {
14721475
// IIS with ISAPI_Rewrite
14731476
$requestUri = $this->headers->get('X_REWRITE_URL');
14741477
$this->headers->remove('X_REWRITE_URL');

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ public function testCookieIsCleared()
134134
public function testToString()
135135
{
136136
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);
137-
138-
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');
137+
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');
139138

140139
$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');
141-
142140
$this->assertEquals('foo=deleted; expires='.gmdate("D, d-M-Y H:i:s T", time()-31536001).'; path=/admin/; domain=.myfoodomain.com; httponly', $cookie->__toString(), '->__toString() returns string representation of a cleared cookie if value is NULL');
141+
142+
$cookie = new Cookie('foo', 'bar', 0, '/', '');
143+
$this->assertEquals('foo=bar; path=/; httponly', $cookie->__toString());
143144
}
144145
}

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

+89
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,95 @@ public function testTrustedProxies()
13731373
// reset
13741374
Request::setTrustedProxies(array());
13751375
}
1376+
1377+
/**
1378+
* @dataProvider iisRequestUriProvider
1379+
*/
1380+
public function testIISRequestUri($headers, $server, $expectedRequestUri)
1381+
{
1382+
$request = new Request();
1383+
$request->headers->replace($headers);
1384+
$request->server->replace($server);
1385+
1386+
$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');
1387+
1388+
$subRequestUri = '/bar/foo';
1389+
$subRequest = $request::create($subRequestUri, 'get', array(), array(), array(), $request->server->all());
1390+
$this->assertEquals($subRequestUri, $subRequest->getRequestUri(), '->getRequestUri() is correct in sub request');
1391+
}
1392+
1393+
public function iisRequestUriProvider()
1394+
{
1395+
return array(
1396+
array(
1397+
array(
1398+
'X_ORIGINAL_URL' => '/foo/bar',
1399+
),
1400+
array(),
1401+
'/foo/bar'
1402+
),
1403+
array(
1404+
array(
1405+
'X_REWRITE_URL' => '/foo/bar',
1406+
),
1407+
array(),
1408+
'/foo/bar'
1409+
),
1410+
array(
1411+
array(),
1412+
array(
1413+
'IIS_WasUrlRewritten' => '1',
1414+
'UNENCODED_URL' => '/foo/bar'
1415+
),
1416+
'/foo/bar'
1417+
),
1418+
array(
1419+
array(
1420+
'X_ORIGINAL_URL' => '/foo/bar',
1421+
),
1422+
array(
1423+
'HTTP_X_ORIGINAL_URL' => '/foo/bar'
1424+
),
1425+
'/foo/bar'
1426+
),
1427+
array(
1428+
array(
1429+
'X_ORIGINAL_URL' => '/foo/bar',
1430+
),
1431+
array(
1432+
'IIS_WasUrlRewritten' => '1',
1433+
'UNENCODED_URL' => '/foo/bar'
1434+
),
1435+
'/foo/bar'
1436+
),
1437+
array(
1438+
array(
1439+
'X_ORIGINAL_URL' => '/foo/bar',
1440+
),
1441+
array(
1442+
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
1443+
'IIS_WasUrlRewritten' => '1',
1444+
'UNENCODED_URL' => '/foo/bar'
1445+
),
1446+
'/foo/bar'
1447+
),
1448+
array(
1449+
array(),
1450+
array(
1451+
'ORIG_PATH_INFO' => '/foo/bar',
1452+
),
1453+
'/foo/bar'
1454+
),
1455+
array(
1456+
array(),
1457+
array(
1458+
'ORIG_PATH_INFO' => '/foo/bar',
1459+
'QUERY_STRING' => 'foo=bar',
1460+
),
1461+
'/foo/bar?foo=bar'
1462+
)
1463+
);
1464+
}
13761465
}
13771466

13781467
class RequestContentProxy extends Request

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ public function testToStringIncludesCookieHeaders()
114114
$bag = new ResponseHeaderBag(array());
115115
$bag->setCookie(new Cookie('foo', 'bar'));
116116

117-
$this->assertContains("Set-Cookie: foo=bar; httponly", explode("\r\n", $bag->__toString()));
117+
$this->assertContains("Set-Cookie: foo=bar; path=/; httponly", explode("\r\n", $bag->__toString()));
118118

119119
$bag->clearCookie('foo');
120120

121-
$this->assertContains("Set-Cookie: foo=deleted; expires=".gmdate("D, d-M-Y H:i:s T", time() - 31536001)."; httponly", explode("\r\n", $bag->__toString()));
121+
$this->assertContains("Set-Cookie: foo=deleted; expires=".gmdate("D, d-M-Y H:i:s T", time() - 31536001)."; path=/; httponly", explode("\r\n", $bag->__toString()));
122122
}
123123

124124
public function testReplace()
@@ -158,7 +158,7 @@ public function testCookiesWithSameNames()
158158
$this->assertContains("Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly", $headers);
159159
$this->assertContains("Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly", $headers);
160160
$this->assertContains("Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly", $headers);
161-
$this->assertContains("Set-Cookie: foo=bar; httponly", $headers);
161+
$this->assertContains("Set-Cookie: foo=bar; path=/; httponly", $headers);
162162

163163
$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
164164
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));

src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ protected function createSubRequest($uri, Request $request)
9090
$server['REMOTE_ADDR'] = '127.0.0.1';
9191

9292
$subRequest = $request::create($uri, 'get', array(), $cookies, array(), $server);
93+
if ($request->headers->has('Surrogate-Capability')) {
94+
$subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
95+
}
9396
if ($session = $request->getSession()) {
9497
$subRequest->setSession($session);
9598
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,23 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers()
137137

138138
$this->assertEquals('Foo', ob_get_clean());
139139
}
140+
141+
public function testESIHeaderIsKeptInSubrequest()
142+
{
143+
$expectedSubRequest = Request::create('/');
144+
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
145+
146+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
147+
$kernel
148+
->expects($this->any())
149+
->method('handle')
150+
->with($expectedSubRequest)
151+
;
152+
153+
$strategy = new InlineFragmentRenderer($kernel);
154+
155+
$request = Request::create('/');
156+
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
157+
$strategy->render('/', $request);
158+
}
140159
}

0 commit comments

Comments
 (0)